Welcome › Forums › General PowerShell Q&A › powershell command?
- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by
Participant.
-
AuthorPosts
-
-
August 25, 2016 at 4:22 am #51828
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 #51832
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 }
-
August 25, 2016 at 4:45 am #51836
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 #51855
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 #51862
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 #51864
Do you know a command that tests hung guest OS I think a test-connection coild be good even in a hung server?
-
-
-
AuthorPosts
- The topic ‘powershell command?’ is closed to new replies.