Skip to content

Instantly share code, notes, and snippets.

@davewilson
Created July 10, 2014 20:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davewilson/88532a8b15f1c0a83449 to your computer and use it in GitHub Desktop.
Save davewilson/88532a8b15f1c0a83449 to your computer and use it in GitHub Desktop.
Email list of logged in users
#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'='recipient@email.com';
'from'='from@email.com';
'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