Files
claudio 368d6fafea Issue
Code backup
2026-05-10 16:59:01 +02:00

43 lines
1.2 KiB
PowerShell

$app = "PS - User Catch"
$ver = "v 0.2"
$start = "Stai eseguendo:"
$exec = "Lo script $app e' in esecuzione."
Write-Host $start, $app, $ver, "`n$exec"
$UserCatch = (173..176) | % {
$Ip = "172.16.91.$_";
$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 ($GetHostname -like 'PC*'){
foreach ($s in $GetHostname) #For Each Server
{
foreach($ServerLine in @(query user /server:$s) -split "\n") #Each Server Line
{
#USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
$Parsed_Server = $ServerLine -split "\s+"
$Parsed_Server[1] #USERNAME
$Parsed_Server[4] #STATE
$Parsed_Server[6] #LOGON TIME
}
}
}
Write-output "`n$IP`t$StatusOut`t$GetHostname"
if ($GetHostname -like 'PC*'){
Write-Output "`n$QueryUser`n"
}
}
Write-Host $UserCatch