1 Reply Latest reply on Feb 7, 2019 12:03 AM by LucD

    Ping VM on Host Scrip

    marco2601 Novice

      I have the following script where it checks if I have ping to an IP of a VM, if it has ping it simply shows me a message that the VM has connection otherwise it deactivates the network interface of the VM aora the inconvenience is that it only validates once the ping, how can I make it validate the ping all the time until it tells me that it lost connection and sends the statement that disconnects the interface of the VM


      Thank you for you help




      $vcenter_server =""

      $vcenter_user ="administrator@taurus.local"

      $vcenter_pwd ="T4urus.2018.v1Center"

      $VMIP= ""



      ##Connect to vCenter

      connect-viserver -server $vcenter_server -User $vcenter_user -Password $vcenter_pwd




      $results = gwmi -query "SELECT * FROM Win32_PingStatus WHERE Address = '$VMIP'"

      if ($results.StatusCode -eq 0) {

      Write-Host "$VMIP hostname is pingable"


      else {

      ##Desconectar vNIC de la VM origen

      Get-VM -Name AD-LAB | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$false -Confirm:$false