Guest User

Test-NetStatus

a guest
Aug 20th, 2017
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Test-NetStatus
  2. {
  3.  [CmdletBinding()]
  4.  Param(
  5. [Parameter(Mandatory=$true,ValueFromPipeLine)][String]$ComputerName)
  6. Process
  7.  {
  8. $aaa = "Host is "
  9. $bbb = " --- "
  10. $ccc = " -- "
  11. $result = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet -ErrorAction SilentlyContinue
  12. If ($result -eq "True") {$result = "Online"}
  13. Else {$result = "Offline"}
  14. IF ($result -eq "Online") {Write-host $aaa$result$bbb$computername -ForegroundColor Green}
  15. Else {Write-host $aaa$result$ccc$computername -ForegroundColor Red}
  16.  }
  17. }
RAW Paste Data