Files
VSC/PowerShell/_Prove/UserCatch/004 - v0.3.ps1
T
claudio 368d6fafea Issue
Code backup
2026-05-10 16:59:01 +02:00

51 lines
1.2 KiB
PowerShell

$app = "PS - User Catch"
$ver = "v 0.3"
$start = "Stai eseguendo:"
$exec = "Lo script $app e' in esecuzione."
Write-Host $start, $app, $ver
Write-Host $exec -fore green
$UserCatch = (180..200) | % {
$Ip = "172.16.82.$_";
$Status = test-connection -computername "$ip" -quiet -count 1;
$StatusOut = switch ($Status) {
'True' {"True"}
'False' {"`0"}
}
if ($Status -like 'True') {
$GetHostname = Resolve-DnsName $ip -ErrorAction Ignore |select -exp NameHost;
$QueryUser = if ($GetHostname -like 'PC*') {
foreach ($s in $GetHostname){
foreach($ServerLine in @(query user /server:$s) -split"\n")
{
$Parsed_Server = $ServerLine -split"\s+"
$Parsed_Server[1]
$Parsed_Server[4]
$Parsed_Server[6]
}
}
}
Write-output "`n$IP`t$StatusOut`t$GetHostname"
if ($GetHostname -like 'PC*') {
Write-Output "`n$QueryUser`n"
}
}
else {
"`0"
}
}
Start-Transcript -Path .\testlog.txt
Write-Host $UserCatch
Stop-Transcript