PowerShell: Script to check for logged users
I’m creating couple powershell scripts which I use in my work. I want to share couple of them with you. So here is a script which look for domain computers and then check who is logged on those online machines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | $ADSearchBase = "OU=Computers,DC=domain,DC=local" $ADFilter = "*" Function Get-LoggedUsersOnComputers { $ADComputersList = Get-ADComputer -SearchBase $ADSearchBase -Filter $ADFilter foreach ( $ADComputer in $ADComputersList ) { Write-Output $ADComputer .Name Try { $ExplorerProcesses = Get-WmiObject -ComputerName $ADComputer .Name -Class win32_process -Filter "Name='explorer.exe'" -ErrorAction Stop } Finally { If ($?) { foreach ( $ExplorerProcess in $ExplorerProcesses ) { Write-Output " $($ExplorerProcess.GetOwner().User)" } } Else { Write-Output " <<< Could not connect" } } } } Get-LoggedUsersOnComputers |
If you have any remark on my script, please, let me know. I will be happy to make it more cute
Recent Comments