Author Posts

August 15, 2017 at 9:41 pm

I have a hyper-v lab with two GCs and several member servers. I'm planning on writing a powershell script/module that will allow me to start up, or shut down, my virtual machines in a particular order. For example, when starting my lab up I'll have the script start the GCs first and wait till they're fully loaded before turning on the member servers. I'm running into a silly, simply looking issue. When I run the following, as a test to check the status every 10 seconds, powershell does nothing. The cursor goes down a few lines and just blinks.

1..100 | %{Get-VM Server1;Sleep 10}

I've done this trick a thousand times and never seen this. If I try the above code with another command, say Get-Service, it works just fine. If I take the Sleep out, it quickly spits out the VM information 100 times.

1..100 | %{Get-VM Server1}

Also, when shutting down, I know I can just check for a vm Status of Off to make sure a machine is off, but when I start a VM, before it's fully loaded, the status will say Running. Is there a way to check whether the VM is fully started (i.e. The screen is ready for me to log in.)?

August 15, 2017 at 9:59 pm

1..100 | % {Get-VM "Server$_"}

To check whether the VM is fully started, test the status of a service on the VM.
For example:

Invoke-Command -ComputerName 'server1' -ScriptBlock { Get-Service -Name Netlogon }

August 16, 2017 at 10:07 pm

Not sure what the first code is about since I'm trying to look up the status of just one machine(Server1) every 10, or so, seconds, but thanks for the second part. 🙂