Monday, June 14, 2021

Powershell Ping report status script

Ping report status script

$result= @()
$names = Get-Content "c:\ip2.txt"
foreach ($name in $names){
  if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
   $Output= "up"
#   Write-Host "up" -ForegroundColor Green
  }
  else{
    $Output= "down"
#    Write-Host "down" -ForegroundColor Red
  }
$hItemDetails=[pscustomobject]@{
IP_address=$name
Status=$Output
}
$result +=$hItemDetails
}
$result | Export-Csv "c:\result2.csv"

No comments: