Home > Blogs > VMware PowerCLI Blog


Managing Virtual Machine questions with PowerCLI

Greetings to all vSphere administrators out there! This post will illustrate another vSphere feature that is interesting from an automation perspective, namely – virtual machine questions.

Virtual Machine questions are questions that must be answered before the operation of a given virtual machine can continue. These questions can arise in different situations. These situations are usually rare but when they occur they block the virtual machine and require attention before the VM can be started again. Let’s see how we can elegantly handle those VM questions with PowerCLI.

One case where a VM question can arise is when you physically copy a VM form one Datastore location to another and then add the newly copied VM to the inventory. In this case the ESX server wants to know if you have moved the VM or copied it. In the first case the UUID of the VM is preserved whereas in the second case a mew UUID is generated. The specifics of this scenario are described in this KB. The important thing here is that when you try to start the VM with PowerCLI you will get an error stating that a VM question must be answered before the VM can start.

PS D:\ > Get-VM QuestionVM | Start-VM

Start-VM : 6/27/2011 1:11:55 PM    Start-VM        This VM has questions that must be answered before the operation can continue.

At line:1 char:29

+ Get-VM *question* | Start-VM <<<<

    + CategoryInfo          : InvalidOperation: (:) [Start-VM], VmBlockedByQuestionException

    + FullyQualifiedErrorId : Client20_VmServiceImpl_WrapInVMQuestionWatchingTask_HasQuestions,VMware.VimAutomation.ViCore.Cmdlets.Commands.StartVM

PS D:\ >

 Now you know a question is preventing this VM from starting. What you want to do is get the question and answer it. This is done with the Get-VMQuestion and Set-VMQuestion cmdlets.

PS D:\ > Get-VMQuestion

 

Text                                               Options              Default

—-                                               ——-              ——-

msg.uuid.altered:This virtual machine might have b {Cancel, I moved it, I copied i

een moved or copied.                                I copied it}        t

In order to configure certain management and networking features, VMware ESX needs to know if this virtual machine was moved or copied.

If you don't know, answer "I copied it".

PS D:\ >

You can answer the question this way:

PS D:\ > Get-VMQuestion | Set-VMQuestion –Option "I copied it"

Confirmation

Answer 'I copied it' to VM question 'msg.uuid.altered:This virtual machine might have been moved or copied.

In order to configure certain management and networking features, VMware ESX needs to know if this virtual machine was moved or copied.

If you don't know, answer "I copied it".

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

PS D:\ >

 Alternatively, you can specify that you want to give the default answer of the question (every VMQuestion has a default answer):

PS D:\ > Get-VMQuestion | Set-VMQuestion –DefaultOption

You can also cancel the Power-On operation by answering “cancel” to the question:

 PS D:\ > Get-VMQuestion | Set-VMQuestion –Option cancel

 

I hope this will be useful.

Regards,

-Angel Evrov, MTS at VMware

10 thoughts on “Managing Virtual Machine questions with PowerCLI

  1. Shawn

    Let’s say I am powering these machines on by importing a CSV file. Not all of the machines fire off the answer, but some of them do. Can I pipe the start-vm stuff to get-question and then set-question in this scenario? That way when I issue the power on command the question will be answered if the machine has one to answer.

    Reply
  2. Angel Evrov

    Sure :)
    # Start the VMs
    Start-VM *
    # Some of the VMs will fire errors
    # Go through the errors and for those that are caused by questions – get the question and answer it:
    $Error | where { $_.Exception -is [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.VmBlock
    edByQuestionException] } | % { Get-VM -Id $_.Exception.VmId | Get-VMQuestion | Set-VMQuestion -Option cancel }

    Reply
  3. Shawn

    So does that script answer “I copied it” for the ones that have a question or does it cancel the power on? I am trying to understand what I see above.

    Reply
  4. Angel Evrov

    It does cancel the power on. I wrote it this way as a precaution so someone won’t copy/past it and answer some questions inappropriately.
    If you want to answer “I copied it” just replace “cancel” with “I copied it”:
    ….. | Set-VMQuestion -Option “I copied it”}

    Reply
  5. Shawn

    How do I pass it to confirm the answer with Yes? I really dont want it to stop and ask me but if there is no way to do that, I can handle it. :-)

    Reply
  6. Angel Evrov

    Yes, the same commands work for version 5 also.
    According to our backward compatibility policy – all functionality is available in the future releases also (unless it’s declared “deprecated”, in which case it will be available in 2 more releases and disappear after that).

    Reply
  7. Aaron

    If anybody runs into Powershell having issues with catching the exception, set the ErrorAction and ErrorVariable parameters on start-vm and catch

    try {
    start-vm $server -ErrorAction Stop -ErrorVariable questionErr
    }
    catch [System.Management.Automation.ActionPreferenceStopException] {
    write-host “Catching exception on the VM question.”
    write-host “Answering with “I moved it”
    get-vm $server | get-vmquestion | Set-VMQuestion -Option “I moved it” -confirm:$false
    }
    catch {
    write-host “Other exception thrown”
    }

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>