Author Posts

August 25, 2016 at 4:22 am

When I ping a IP in powershell it does the pings followed by a ping statistics. I use it to ping guest OS (hyper-v VM) from my host OS ie ping 37.221.***.36 with ping destination Host unreachable If the guest VM is offline. When a Destination Unreachable is created can it trigger a pipe chain command | Save-vm -Name (***); Stop-vm -force -Name (***); Start-vm -asjob -Name (***). I just want a chain pipe command that when the host is unreachable the guest OS is shutdown and restarted?

August 25, 2016 at 4:45 am

I think it would be better to use the PowerShell native cmdlet Test-Connection instead of the ping.exe command.

Example:

$ComputerName = 'vmguest01'
if (-not (Test-Connection -ComputerName $ComputerName -Quiet)) {
    Save-VM -Name $ComputerName
    Stop-VM -Name $ComputerName -Force
    Start-VM -Name $ComputerName -AsJob
}
  • This reply was modified 2 years, 1 month ago by  Daniel Krebs.

August 25, 2016 at 4:45 am

Instead of using ping.exe for this, I'd recommend the Test-Connection cmdlet. It does the same thing, but is easier to script around. In this case, I'd use the -Quiet switch (which just returns $true if the host is online, $false if it's not). Something like this:

if (-not (Test-Connection $yourIPAddress -Quiet))
{
    # Your VM commands here if it's offline
}

August 25, 2016 at 8:37 am

Is there a command where I do Test-Connection 192.168.(***).104 it shows results and make a pipe chain command ie Test-Connection 192.168.(***).104 | if (Test-Connection -Quiet) | Save-vm -Name New; Stop-vm -Name New; Start-vm -Name New

This command does not work but I want to see the test connection results

August 25, 2016 at 9:41 am

Do you know a commanf=d that tests hung guest OS I think a test-connection coild be good even in a hung server

August 25, 2016 at 9:42 am

Do you know a command that tests hung guest OS I think a test-connection coild be good even in a hung server?