Powershell: ping: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Mlepla (talk | contribs)
Created page with 'Skript näitab kas pingitav aadress on edukas või mitte $Srvname = Read-Host "SISESTA HOSTI NIMI VÕI IP AADRESS" $ping = new-object System.Net.NetworkInformation.Ping $shell …'
 
Mlepla (talk | contribs)
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
Skript näitab kas pingitav aadress on edukas või mitte
<Source lang="powershell">


$Srvname = Read-Host "SISESTA HOSTI NIMI VÕI IP AADRESS"
# Name: ping1.ps1
$ping = new-object System.Net.NetworkInformation.Ping
# Author: Marek Lepla
# Date: 31.05.2012
# Comment: See skript pingib kõiki web-i aadresse, mis on kirjutatud CSV faili.


$shell = New-Object -ComObject wscript.shell
$test = $ping.send($Srvname)


if (!$?)
 
{
 
$shell.popup("KAHJUKS EI LEIDNUD IP AADRESS MIS SINU HOSTILE VASTAB")
$ping = "C:\Users\Marek\Desktop\ping.csv"
}
$csv = Import-CSV $ping
elseif ($test.status -eq "LEITUD")
$smtpServer = ""
{
 
$shell.popup("LEITUD")
foreach($item in $csv){
}
    $server = $item.HostName
Else
    $ip = $item.IpAddress
{
 
$status = $test.status
    $ping = new-object System.Net.NetworkInformation.Ping
$shell.popup("$status")
    $rslt = $ping.send($ip)
    #Write-host $rslt
        if ($rslt.status.tostring() –eq "Success") {
            write-host ping tootas $server with $ip -ForegroundColor Green
          # write-host $rslt.status.tostring()
          }
        else {
            write-host ping eba6nnestus $server with $ip -ForegroundColor Red
}
}
#end
$ping = $null

Latest revision as of 19:32, 31 May 2012

<Source lang="powershell">

  1. Name: ping1.ps1
  2. Author: Marek Lepla
  3. Date: 31.05.2012
  4. Comment: See skript pingib kõiki web-i aadresse, mis on kirjutatud CSV faili.



$ping = "C:\Users\Marek\Desktop\ping.csv" $csv = Import-CSV $ping $smtpServer = ""

foreach($item in $csv){

   $server = $item.HostName
   $ip = $item.IpAddress
   $ping = new-object System.Net.NetworkInformation.Ping
   $rslt = $ping.send($ip)
   #Write-host $rslt
       if ($rslt.status.tostring() –eq "Success") {
           write-host ping tootas $server with $ip -ForegroundColor Green
          # write-host $rslt.status.tostring()
          }
       else {
           write-host ping eba6nnestus $server with $ip -ForegroundColor Red

} $ping = $null