368d6fafea
Code backup
29 lines
772 B
PowerShell
29 lines
772 B
PowerShell
$app = 'PS - User Catch'
|
|
$ver = 'v 0.1'
|
|
|
|
Write-Host $app, $ver,"`n UserCatch"
|
|
|
|
$SweepIp = (193..198) | % {
|
|
$Ip="172.16.82.$_";
|
|
$Status=test-connection -computername "$ip" -quiet -count 1;
|
|
|
|
$StatusOut = switch ($Status) {
|
|
'True' {"True"}
|
|
'False' {"`0"}
|
|
}
|
|
|
|
$GetHostname=Resolve-DnsName $ip -ErrorAction Ignore |select -exp NameHost;
|
|
|
|
$QueryUser=if ($StatusOut -like 'True'){
|
|
if ($GetHostname -like 'PC*'){
|
|
(query user /server:$GetHostname) -split "`n" -replace '\s\s+', ';' | convertfrom-csv -Delimiter ';'
|
|
}
|
|
}
|
|
|
|
Write-output "`n$IP `t $StatusOut `t $GetHostname"
|
|
if ($GetHostname -like 'PC*'){
|
|
Write-Output "`n$QueryUser"
|
|
}
|
|
}
|
|
|
|
Write-Host $SweepIp |