Created
July 10, 2014 20:24
-
-
Save davewilson/88532a8b15f1c0a83449 to your computer and use it in GitHub Desktop.
Email list of logged in users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get usernames and email | |
#from http://www.reddit.com/r/PowerShell/comments/2acnqh/computerlist_filter_by_user/ | |
$MachineList = Get-Content -Path H:\ListOfMachines.txt; # One system name per line | |
foreach ($machine in $MachineList){ | |
$params = @{'ComputerName'=$machine; | |
'Namespace'='root\cimv2'; | |
'Class'='Win32_ComputerSystem'; | |
'ErrorAction'='SilentlyContinue' | |
} | |
$user = (Get-WmiObject @params).UserName | |
if ($user -notlike 'domain\*') | |
{ | |
$machine + ": " + $user | Out-File loggedinusers.txt -Append | |
} | |
} | |
$mail = @{'to'='[email protected]'; | |
'from'='[email protected]'; | |
'smtpserver'='mail.email.com'; | |
'subject'='Logged in users'; | |
'body'=(Get-Content -Path loggedinusers.txt | Out-String) | |
} | |
Send-MailMessage @mail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment