Altere a ordem de Boot de máquinas virtuais Script Hyper-V
Se você precisar alterar a ordem de inicialização de uma máquina virtual programaticamente (de modo que ele vai iniciar primeiramente pela placa de rede – por exemplo), é relativamente simples:
# Function for handling WMI jobs / return values Function ProcessResult($result, $successString, $failureString) { #Return success if the return value is "0" if ($result.ReturnValue -eq 0) {write-host $successString} #If the return value is not "0" or "4096" then the operation failed ElseIf ($result.ReturnValue -ne 4096) {write-host $failureString " Error value:" $result.ReturnValue} Else {#Get the job object $job=[WMI]$result.job #Provide updates if the jobstate is "3" (starting) or "4" (running) while ($job.JobState -eq 3 -or $job.JobState -eq 4) {write-host $job.PercentComplete "% complete" start-sleep 1 #Refresh the job object $job=[WMI]$result.job} #A jobstate of "7" means success if ($job.JobState -eq 7) {write-host $successString} Else {write-host $failureString write-host "ErrorCode:" $job.ErrorCode write-host "ErrorDescription" $job.ErrorDescription} } } # Prompt for the Hyper-V Server to use $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)" # Prompt for the virtual machine to use $VMName = Read-Host "Specify the name of the virtual machine" # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get the virtual machine object $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer # SettingType = 3 ensures that we do not get snapshots $SystemSettingData = $VM.getRelated("Msvm_VirtualSystemSettingData") | where {$_.SettingType -eq 3} # Change the boot order. This is an array of four entries. # The first entry in the array is the first boot choice. # The second is the second, and so on. The values map as follows: # # 0 == Floppy # 1 == CD # 2 == IDE # 3 == Net # # The command below sets up the boot order as: # Network, CD, IDE, Floppy $SystemSettingData.BootOrder = @(3,1,2,0) # Commit the changes $result = $VMMS.ModifyVirtualSystem($VM, $SystemSettingData.GetText(1)) # Check to see that it all worked ProcessResult $result "BIOS settings have been updated." "Failed to update BIOS settings." O mesmo artigo pode ser encontrado em inglês no site: http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/01/13/change-a-virtual-machine-boot-order-hyper-v-script.aspx Grande abraço a todos!
Publicado em julho 18, 2011, em Hyper-V. Adicione o link aos favoritos. Deixe um comentário.
Deixe um comentário
Comentários 1