Guest User

Finding logged in users using computer names

a guest
Dec 5th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param($searchstr)
  2. $list=@()
  3. foreach($comp in Get-ADComputer -Filter "Name -like '*$searchstr*'"){
  4. if(test-connection -computername $comp.name -count 1 -ErrorAction SilentlyContinue){
  5.     $obj = New-Object System.Object
  6.     $obj | add-member -type NoteProperty -Name Computername -Value $comp.name
  7.     $obj | add-member -type NoteProperty -Name User -Value (gwmi win32_computersystem -ComputerName $comp.name | Select-Object Username -ErrorAction SilentlyContinue).username
  8.     $list+=$obj
  9.     }
  10. }
  11. return $list | Format-table -AutoSize -HideTableHeaders
Advertisement
Add Comment
Please, Sign In to add comment