$base = ((Get-NetIPConfiguration |
Where-Object IPv4DefaultGateway |
Select-Object -First 1).IPv4Address.IPAddress -replace '\d+$','')
$found = foreach ($n in 101..254) {
$ip = "$base$n"
Write-Host "Проверяю $ip ... " -NoNewline
ping.exe -n 1 -w 200 $ip | Out-Null
if ($LASTEXITCODE -eq 0) {
$name = ''
try {
$name = [Net.Dns]::GetHostEntry($ip).HostName
} catch {}
$adminShare = Test-Path "\\$ip\ADMIN$" -ErrorAction SilentlyContinue
Write-Host "НАЙДЕН $name ADMIN$: $adminShare" -ForegroundColor Green
[pscustomobject]@{
IP = $ip
Computer = $name
AdminShare = $adminShare
}
}
else {
Write-Host "нет ответа" -ForegroundColor DarkGray
}
}
$found | Format-Table -AutoSize
$found.IP | Set-Content .\pcs.txt