obeckham 发表于 2018-9-3 10:34:54

PowerShell实战1:Ping_Test

function Ping_Test {  PROCESS {
  $ping = $false
  $results = Get-WmiObject -query `
  "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
  $RT = $results.ResponseTime
  $TTL = $results.ResponseTimeToLive
  foreach ($result in $results) {
  if ($results.StatusCode -eq 0) {
  if ($TTL -ge 98 -and $TTL -le 128)
  {Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL,It is a Windows host." -ForegroundColor Green }
  else
  {Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL, It is NOT a Windows host." -ForegroundColor Blue}
  }
  else {
  Write-Host "`n$_ Ping failed!" -ForegroundColor Red
  }
  }
  }
  }
  cls
  Get-Content c:\IP.txt | Ping_Test

页: [1]
查看完整版本: PowerShell实战1:Ping_Test