# powershell command?

**URL:** <https://forums.powershell.org/t/powershell-command/7064>\
**Category:** PowerShell Help\
**Created:** [August 24, 2016, 10:52pm UTC](https://forums.powershell.org/t/powershell-command/7064 "2016-08-24T22:52:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![craig-redfern](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@craig-redfern](https://forums.powershell.org/u/craig-redfern)\
**Post date:** [August 24, 2016, 10:52pm UTC](https://forums.powershell.org/t/powershell-command/7064/1 "2016-08-24T22:52:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [August 24, 2016, 11:15pm UTC](https://forums.powershell.org/t/powershell-command/7064/2 "2016-08-24T23:15:27Z")

</div>

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
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [August 24, 2016, 11:15pm UTC](https://forums.powershell.org/t/powershell-command/7064/3 "2016-08-24T23:15:30Z")

</div>

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
}
```

---

<div class="post-metadata">

**Author:** ![craig-redfern](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@craig-redfern](https://forums.powershell.org/u/craig-redfern)\
**Post date:** [August 25, 2016, 3:07am UTC](https://forums.powershell.org/t/powershell-command/7064/4 "2016-08-25T03:07:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![craig-redfern](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@craig-redfern](https://forums.powershell.org/u/craig-redfern)\
**Post date:** [August 25, 2016, 4:11am UTC](https://forums.powershell.org/t/powershell-command/7064/5 "2016-08-25T04:11:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![craig-redfern](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@craig-redfern](https://forums.powershell.org/u/craig-redfern)\
**Post date:** [August 25, 2016, 4:12am UTC](https://forums.powershell.org/t/powershell-command/7064/6 "2016-08-25T04:12:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/powershell-command/7064/7 "2024-05-16T20:40:38Z")

</div>


