PowerCLI

 View Only
  • 1.  Ping host from ip list with powershell

    Posted Jan 29, 2018 09:52 AM

    Hello, I would like to ping some or all host in vcenter in some specific time, Is possible to do by script?



  • 2.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 09:58 AM

    I found this, but I didn't test yet

    $Output= @()

    $names = Get-content "hnames.txt"

    foreach ($name in $names){

      if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){

       $Output+= "$name,up"

       Write-Host "$Name,up"

      }

      else{

        $Output+= "$name,down"

        Write-Host "$Name,down"

      }

    }



  • 3.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 10:00 AM

    You will have to specify what kind of ping you want.

    1. A regular ping, which you can do with the Test-Connection cmdlet
    2. A 'vmkping', which you can do via Get-EsxCli and then $esxcli.network.diag.ping()


  • 4.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 10:05 AM

    for vmkping ssh in the host should be enabled? 



  • 5.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 10:10 AM

    No



  • 6.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 10:14 AM

    Thanks for clarification LucD, I think Test-Connection cmdlet is in half for now, I will test this



  • 7.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 12:35 PM

    Hi LucD

    I proceeded with:

    get-content C:\Users\gemela\Desktop\Ping\hnames.txt.txt| % {new-object psobject -property @{ComputerName=$_; Reachable=(test-connection -computername $_ -quiet -count 1)} } | Export-Csv C:\Users\gemela\Desktop\ping.txt

    I would like to put some extra things,

    Like csv output with hostname, Ip, up and down column with result (true or false) and if possible to set email in case of some ip is not reachable.



  • 8.  RE: Ping host from ip list with powershell

    Posted Jan 29, 2018 01:35 PM

    Try something like this

    $report = foreach($name in Get-Content C:\Users\gemela\Desktop\Ping\hnames.txt){

        $result = Test-Connection -ComputerName $name -Quiet

        New-Object PSObject -Property @{

            ComputerName = $names

            IP = (Resolve-DnsName -Name $name).IPAddress

            Responding = $result

        }

        if(-not $result){

            Send-MailMessage -Subject 'Host $name does not reply' -To me@domain.com -From test@domain.com -SmtpServer mail.domain.com

        }

    }

    $report | Export-Csv .\report.csv -UseCulture



  • 9.  RE: Ping host from ip list with powershell

    Posted Jan 30, 2018 08:50 AM

    Thanks LucD, I will test it this week.