Adding DHCP server support for PXE BIOS and UEFI Booting – Version 2
I had some time and thought I would look at my old DHCP Options script. Well, it was not only dated, but somewhere down the line it stopped working as well as it used to.
I made a replacement. Short and simple. It not only is a lot more streamlined, it also is targeted. It will only make changes to the DHCP Scope you specify.
It doesn’t have error checking for the policies yet, so it’ll try to add them every time it is run and will fail out but not cause any issues.
A little red never killed anyone right? Actually, don’t answer that…
This script will prompt you for the following information.
- Name of the DHCP server you want to connect to.
- The Scope ID (e.g. 10.20.30.0) to modify.
- The IP address of the server running WDS (PXE) services.
#Requires -Version 4
#Requires -RunAsAdministrator
<#
====================================================
Checks if being run on a DHCP server and supported
OS version and if not, breaks out of the script.
====================================================
#>
if((Get-WindowsFeature -Name "Dhcp").Installed -eq $True) {
if(([System.Environment]::OSVersion).Version -ge 6.2) {
Import-Module DhcpServer
}else{
Write-Host "`n ERROR: Please run this script on a supported OS." -ForegroundColor Red
Write-Host " ERROR:"(Get-WmiObject -class Win32_OperatingSystem).Caption.Trim()"is not supported.`n" -ForegroundColor Red
Break
}
} else {
Write-Host "`n ERROR: Please run this script on a DHCP server.`n" -ForegroundColor Red
Break
}
<#
=================================================
Script Variables
=================================================
#>
$DHCP_Server = Read-Host -Prompt "Enter the DHCP server name"
$DHCP_Scope = Read-Host -Prompt "Enter the Scope ID (e.g. 10.20.30.0)"
$WDS_Server = Read-Host -Prompt "Enter the IP of the server running WDS (PXE)"
If(!($DHCP_Server) -or !($DHCP_Scope) -or !($WDS_Server)){
Write-Host "`n ERROR: IP was not entered!" -ForegroundColor Red
Break
}
$VendorClassUEFIx64 = @{
Name = "PXEClient UEFI (x64)"
Description = "PXEClient UEFI (x64)"
Type = "Vendor"
Data = "PXEClient:Arch:00007"
}
$VendorClassUEFIx86 = @{
Name = "PXEClient UEFI (x86)"
Description = "PXEClient UEFI (x86)"
Type = "Vendor"
Data = "PXEClient:Arch:00006"
}
$VendorClassBIOS = @{
Name = "PXEClient BIOS (x86 & x64)"
Description = "PXEClient BIOS (x86 & x64)"
Type = "Vendor"
Data = "PXEClient:Arch:00000"
}
Add-DhcpServerv4Class @VendorClassUEFIx64 -ComputerName $DHCP_Server
Add-DhcpServerv4Class @VendorClassUEFIx86 -ComputerName $DHCP_Server
Add-DhcpServerv4Class @VendorClassBIOS -ComputerName $DHCP_Server
Add-DhcpServerv4Policy -Name "PXEClient UEFI (x64)" -ScopeId $DHCP_Scope -Condition OR -VendorClass EQ,"PXEClient UEFI (x64)*"
Add-DhcpServerv4Policy -Name "PXEClient UEFI (x86)" -ScopeId $DHCP_Scope -Condition OR -VendorClass EQ,"PXEClient UEFI (x86)*"
Add-DhcpServerv4Policy -Name "PXEClient BIOS" -ScopeId $DHCP_Scope -Condition OR -VendorClass EQ,"PXEClient BIOS (x86 & x64)*"
Set-DhcpServerv4OptionValue -ComputerName $DHCP_Server -ScopeId $DHCP_Scope -PolicyName "PXEClient BIOS" -OptionId 66 -Value $WDS_Server
Set-DhcpServerv4OptionValue -ComputerName $DHCP_Server -ScopeId $DHCP_Scope -PolicyName "PXEClient BIOS" -OptionId 67 -Value "boot\x86\wdsnbp.com"
Set-DhcpServerv4OptionValue -ComputerName $DHCP_Server -ScopeId $DHCP_Scope -PolicyName "PXEClient UEFI (x64)" -OptionId 66 -Value $WDS_Server
Set-DhcpServerv4OptionValue -ComputerName $DHCP_Server -ScopeId $DHCP_Scope -PolicyName "PXEClient UEFI (x64)" -OptionId 67 -Value "boot\x64\wdsmgfw.efi"
Set-DhcpServerv4OptionValue -ComputerName $DHCP_Server -ScopeId $DHCP_Scope -PolicyName "PXEClient UEFI (x86)" -OptionId 66 -Value $WDS_Server
Set-DhcpServerv4OptionValue -ComputerName $DHCP_Server -ScopeId $DHCP_Scope -PolicyName "PXEClient UEFI (x86)" -OptionId 67 -Value "boot\x86\wdsmgfw.efi"