Friday, 7 April 2017

simple try catch to find servers ping status

$servers =Get-Content -Path C:\servers.txt.txt

foreach ($server in $servers) {


try

{

Test-Connection -ComputerName $server -Count 2 -ErrorAction Stop | ft -AutoSize

}


catch

{
Write-Host $_.Exception.Message -ForegroundColor Green

}
}


No comments:

Post a Comment

Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress

#Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress # use...