Invoke-VMShutdown - Parameters, Start-VM - test-wmijob

Nov 14, 2009 at 5:13 PM
Edited Nov 14, 2009 at 5:14 PM

Hello all,

I'm new with the PS Library for Hyper-V and already took a look in the pdf-doc. But I'm not able to get my needs scripted. One thing first: sorry for my newbieness.

Background / planned scenario:

One Script which pauses or shuts down all running VMs [before backup task] 

get-vm -running | Invoke-VMShutdown machinexx -Wait

One Script which resumes or starts all not running VMs [after backup task] (Is there a way to determine all not running VMs)

 get-vm -running | Start-VM machinexx -Wait

The first error I get is that something must be wrong with the parameter "-wait" -> how to exactly use this ?

The second "error" appears when I try to start a VM out of an "off-state":

WARNUNG: The job to Change state of VM xpjob1 to Running  is still running in the background.
 You can check its progress with Test-wmiJob or Test-wmiJob -statusOnly using
the following job id:

OK trying to check the progress of the running job i do the following:

test-wmijob \\TGKFR710\root\virtualization:Msvm_ConcreteJob.InstanceID="B18C8110-F31F-4395-8141-CD51FADD451F"

error: Test-WMIJob : Die Argumenttransformation für den Parameter "Job" kann nicht ver
arbeitet werden. Der Wert "\\TGKFR710\root\virtualization:Msvm_ConcreteJob.Inst
anceID=B18C8110-F31F-4395-8141-CD51FADD451F" kann nicht in den Typ "System.Mana
gement.ManagementObject" konvertiert werden. Fehler: "Der Parameter ist ungülti
g. "
Bei Zeile:1 Zeichen:12
+ Test-WMIJob <<<<  \\TGKFR710\root\virtualization:Msvm_ConcreteJob.InstanceID=
    + CategoryInfo          : InvalidData: (:) [Test-WMIJob], ParameterBindin.
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Test-WMIJob

 Sorry for this extra long post! I hope you will help me. -> Are there any documents with more examples and maybe detailed explanations for non-PS-geeks?


Thanks in advance and best regards,


Nov 24, 2009 at 3:29 PM

no worries about being a newbie :-)

 get-vm -running | Invoke-VMShutdown machinexx -Wait

Invoke-VMShutdown is a bit different from the other commands, because -wait tells them to wait until the hyper-V service reports it has finished. With shutdown the VM gets the shutdown instruction but that is not the end of the command so we must poll the machine to see if it has shut down, and if it fails to shutdown we need a timeout. So there is a parameter $ShutdownTimeOut  which takes an integer value for example -shutdownTimeOut 300 will wait 5 minutes.

get-vm -running | Start-VM machinexx -Wait

Get-vm  is trying to pass machines into the the VM parameter of Start-VM and Machinexx is trying to be the VM parameter  get-vm -stopped -saved  | Start  -Wait  will work

(note get-vm takes -running -suspended -stoped  , and you can use them in any combination).

The warning comes up because the start-up request is still running - the VM may not be able start.  I used the same script and lots of places and sometimes the job comes back with single quotes in the name and sometimes with double quotes. When you pass the name to test-wmiJob you need to put the other kind of quotes round the name. so in this case you need

 test-wmijob '\\TGKFR710\root\virtualization:Msvm_ConcreteJob.InstanceID="B18C8110-F31F-4395-8141-CD51FADD451F"'

 Hope that helps. I'm not really sure where to point you for more information - did you want something for starting powershell or understanding hyperv ?



Nov 25, 2009 at 2:27 PM

Thank you for your answer.

The following commmand won't work for me as expected (it always tells me that no parameter "-Wait" is known, unless I do "-Wait 300" or "-Wait"):

-Wait does only work for Starting the VM's (Start-VM machinexx -Wait) but now in the command below

get-vm -running | Invoke-VMShutdown machinexx -Wait

My solution for the scenario would be: (Or do I have to pay attention on sth. else?):

get-vm -running | Invoke-VMShutdown -shutdownTimeOut 500

But how to query if the command succeded and how to differentiate those cases (success/fail)? -> With get-vm -running and then?


It would be nice if you could point me to more information about powershell (scripting).

Thanks for your help and regards,


Nov 26, 2009 at 12:49 AM

sorry, I only picked up one point

if you pipe VMs into Invoke-VMShutdown , the you don't specify MachineXX , so this command get-vm -running | Invoke-VMShutdown -shutdownTimeOut 500

is the right one, the usual reason for doing this is if you need to be sure (for example) all your machines are shutdown before you stop the domain controller.  If the timeout expires an the machine is not in the stopped state then it hung on shutdown. So you could get-vm -running | stop-vm -force  it off.  has some good suggestions of places to learn about powershell in the comments.



Dec 4, 2009 at 7:55 AM

Thanks for your help!

But there is one problem left for me:

I try to get a list of "objects" where VMElementName doesn't equal a specific machine name with the following command:

get-vm -running | where {$_.VMElementName -ne 'machinexx'}

But none of the comparison parameters (-eq, -ne ...) work.

Background: Pipeing the result to "Invoke-VMShutdown" to shut down only a few machines.

Could you please tell me how to solve this little problem?


Thanks in advance!

Dec 8, 2009 at 11:01 PM

OK, I did a bad thing.

Because when you get disk etc you might be getting them from from different VMs I added a column when they are displayed named VMelementName. VM's have a "name", which is actually a GUID, and display name which is "ElementName". I'm not at a machine where I can check right now ,but I think I labelled the column for VMs VMElementname not ElementName. That's the name you need to use .

What I should do is go back and add a VMElementName property in the Get functions, rather than in the XML that controls formatting. I may do that over the Christmas holidays.