when a start a vm with the command start-vm -vm xxx
i have a question:
Did you move this virtual machine, or did you copy
it?
If you don't know, answer "I copied it".
how respond to this question with the command powershell
thanks
Hello.
Note: This discussion was moved from the Community Website Help community to the VMware vSphere™ PowerCLI community.
Good Luck!
You can use the Get-VMQuestion and Set-VMQuestion cmdlets to retrieve and answer to the question.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
#Change your answer to whatever you need examplae Cancel or "I copied it"
#See http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-VMQuestion.html
$Error | where { $_.Exception -is [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.VmBlock
edByQuestionException] } | % { Get-VM -Id $_.Exception.VmId | Get-VMQuestion | Set-VMQuestion -Option "I copied it" }
Start-VM -vm XX
I've used this in v4.1 but on my v5.5 systems, "I moved it" doesn't work. I add a bunch of vms from a replicated datastore and then try to start them. Here are the relevant lines of code (unchanged between versions):
# $drVms is a list of all the vm objects
$drVms | Start-VM -Confirm:$false
# answer the vm questions
Get-VMQuestion | Set-VMQuestion -Option 'I Moved It' -Confirm:$false
I get:
Set-VMQuestion : 11/14/2013 11:48:00 AM Set-VMQuestion Option not found: 'I Moved It'.
At line:1 char:32
+ Get-VMQuestion | Set-VMQuestion <<<< -Option 'I Moved It' -Confirm:$false
+ CategoryInfo : InvalidArgument: (:) [Set-VMQuestion], InvalidArgument
+ FullyQualifiedErrorId : Core_SetVmQuestion_GetChosenOption_OptionNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVMQuestion
As you can see, I even tried matching the case from the question dialog. Tried all upper and all lower too but nothing works. I wish we could provide some definitive code for the answers rather than arbitrary strings. There should only be so many questions and possible answers. Maybe just an index into the radio buttons. That way the question set can be expanded without updating anything.
Is this form no longer supported? I'll try unwrapping this to get the vm object explicitly into the set-vmquestion command.
To add to my question, here is the data in the 'question':
> Get-VMQuestion | fl
VMId : VirtualMachine-vm-292
VM : lnxtest1
QuestionId : _vmx1
Text : This virtual machine might have been moved or copied. In order to configure certain management and networ
king features, VMware ESX needs to know if this virtual machine was moved or copied. If you don't know, a
nswer "I Copied It".
Options : {Cancel, button.uuid.movedTheVM, button.uuid.copiedTheVM}
DefaultOption : button.uuid.copiedTheVM
Uid : /VIServer=acs\da-cjc@w86sanpdhvc01:443/VirtualMachine=VirtualMachine-vm-292/VMQuestion=_vmx1/
ExtensionData : VMware.Vim.VirtualMachineQuestionInfo
The formatting here is messed up but it looks like the text is listing the message in the dialog, the Options should be the 'options' in the dialog and the default should be what ever that is (copied). Since one option is 'Cancel' but the others reference button uuids, this looks like a bug. I'm going to try this in v5.1.
OK, in v5.5.0, 1331820, you have to respond: "Cancel", "button.uuid.movedTheVM", or "button.uuid.copiedTheVM".
Seriously...
first, find out the value of option by using the command "$vm | Get-VMQuestion | fl"
In my enviroment, the command "$vm | Get-VMQuestion | Set-VMQuestion -Option "button.uuid.movedTheVM" -Confirm:$false" works out.