Created
March 21, 2017 11:49
-
-
Save philippwiddra/49d24e2f39369e7f2f6bb25278277699 to your computer and use it in GitHub Desktop.
This file contains 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
$pcs = (Get-ADComputer -Filter * | ? { Test-Connection $_.DNSHostName -Quiet -Count 1 }).DNSHostName | |
Invoke-Command -ComputerName $pcs -ScriptBlock { | |
$result = query user | |
$success = $result[1] -match "^[> ]([^ ]+) +([^ ]+) +([0-9]+) +([^ ]+) +([^ ]+) +(.+)$" | |
if ($success) { | |
New-Object PSObject -Property @{ | |
PC = $env:computername; | |
Benutzername = $Matches[1]; | |
Sitzungsname = $Matches[2]; | |
Id = $Matches[3]; | |
Status = $Matches[4]; | |
Leerlauf = $Matches[5]; | |
Anmeldezeit = $Matches[6]; | |
} | |
} else { | |
Write-Error "Parse Error whilst parsing: $result" | |
} | |
} | Out-GridView -Title "Currently Logged On Users" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment