Skip to content

Instantly share code, notes, and snippets.

@R41D3NN
Created May 11, 2017 20:03
Show Gist options
  • Select an option

  • Save R41D3NN/9e6ffdcfdf3d5b641f2fe2a2ef1f4d72 to your computer and use it in GitHub Desktop.

Select an option

Save R41D3NN/9e6ffdcfdf3d5b641f2fe2a2ef1f4d72 to your computer and use it in GitHub Desktop.
Remove the PXE boot sequence from a Hyper-V virtual machine.
Function Remove-HyperVPXEBoot {
<#
.Synopsis
Remove the PXE boot sequence from a Hyper-V virtual machine.
.PARAMETER ComputerName
The name of the Hyper-V computer where the targeted VM is hosted.
.PARAMETER VMName
The name of the Hyper-V virtual machine to remove PXE boot from.
.OUTPUTS
Returns a boolean stating if the operation was successful.
.EXAMPLE
Remove-HyperVPXEBoot -ComputerName "HYPERVSRV01" -VMName "WIN2016SRV01"
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false)]
[String] $ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory=$true)]
[String] $VMName
)
Try {
$oldBootOrder = Get-VMFirmware -VMName "$VMName" -ComputerName "$ComputerName" | Select-Object -ExpandProperty BootOrder
If ($oldBootOrder -eq $null) {
Return $false
}
$newBootOrder = $oldBootOrder | Where-Object { $_.BootType -ne "Network" }
If ($newBootOrder -eq $null) {
Return $false
}
Set-VMFirmware -VMName "$VMName" -ComputerName "$ComputerName" -BootOrder $NewBootOrder
Return $true
}
Catch {
Write-Error $_.Exception.Message
Return $false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment