Skip to content

Instantly share code, notes, and snippets.

@philippwiddra
Created March 21, 2017 11:49
Show Gist options
  • Save philippwiddra/49d24e2f39369e7f2f6bb25278277699 to your computer and use it in GitHub Desktop.
Save philippwiddra/49d24e2f39369e7f2f6bb25278277699 to your computer and use it in GitHub Desktop.
$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