--- step
initialize
--- hostctl
{"host": "ssh://admin@dhcp01:22?shell=powershell&pathname=windows&timeout=120", "password": false, "script": "$ErrorActionPreference = 'Stop'/n$p = ConvertFrom-Json '{/"ScopeId/": /"10.0.0.0/", /"ComputerName/": /"dhcp01/", /"Shared/": true, /"Policies/": [{/"Name/": /"ipxe/", /"UserClass/": /"iPXE/", /"VendorClass/": /"/", /"MacAddress/": /"/", /"Order/": 1, /"Classes/": [{/"Name/": /"iPXE/", /"Type/": /"User/", /"Data/": /"iPXE/"}], /"Options/": [{/"Id/": 67, /"Value/": [/"boot.ipxe/"]}]}]}'/n$cmdlets = [bool](Get-Command Add-DhcpServerv4Policy -ErrorAction SilentlyContinue)/nif (-not $cmdlets -and -not $p.Shared) {/n  throw 'NETBOOT-NO-POLICY-CMDLETS'/n}/nforeach ($pol in $(if ($cmdlets) { $p.Policies } else { @() })) {/n  $common = @{}/n  if ($p.ComputerName) { $common['ComputerName'] = $p.ComputerName }/n  $existing = Get-DhcpServerv4Policy -ScopeId $p.ScopeId -Name $pol.Name @common -ErrorAction SilentlyContinue/n  if ($existing -and $p.Shared) { continue }/n  foreach ($cls in $pol.Classes) {/n    $have = Get-DhcpServerv4Class -Name $cls.Name -Type $cls.Type @common -ErrorAction SilentlyContinue/n    if (-not $have) {/n      Add-DhcpServerv4Class -Name $cls.Name -Type $cls.Type -Data $cls.Data @common/n    }/n  }/n  if (-not $existing) {/n    $new = @{ Name = $pol.Name; ScopeId = $p.ScopeId; Condition = 'AND' }/n    if ($pol.UserClass)   { $new['UserClass']   = @('EQ', $pol.UserClass) }/n    if ($pol.VendorClass) { $new['VendorClass'] = @('EQ', $pol.VendorClass) }/n    if ($pol.MacAddress)  { $new['MacAddress']  = @('EQ', $pol.MacAddress) }/n    Add-DhcpServerv4Policy @new @common/n  }/n  if ($pol.Order) {/n    Set-DhcpServerv4Policy -Name $pol.Name -ScopeId $p.ScopeId -ProcessingOrder $pol.Order @common/n  }/n  foreach ($o in $pol.Options) {/n    Set-DhcpServerv4OptionValue -PolicyName $pol.Name -ScopeId $p.ScopeId -OptionId $o.Id -Value $o.Value @common/n  }/n}/nConvertTo-Json @{ ok = $true }/n"}
--- hostctl
{"host": "ssh://admin@dhcp01:22?shell=powershell&pathname=windows&timeout=120", "password": false, "script": "$ErrorActionPreference = 'Stop'/n$p = ConvertFrom-Json '{/"ScopeId/": /"10.0.0.0/", /"IPAddress/": /"10.0.0.10/", /"ClientId/": /"aa-bb-cc-dd-ee-ff/", /"Name/": /"web01/", /"ComputerName/": /"dhcp01/", /"Options/": [{/"Id/": 3, /"Value/": [/"10.0.0.1/"]}, {/"Id/": 6, /"Value/": [/"10.0.0.53/", /"10.0.0.54/"]}, {/"Id/": 15, /"Value/": [/"example.com/"]}, {/"Id/": 1, /"Value/": [/"255.255.255.0/"]}, {/"Id/": 28, /"Value/": [/"10.0.0.255/"]}]}'/n$common = @{}/nif ($p.ComputerName) { $common['ComputerName'] = $p.ComputerName }/n$existing = Get-DhcpServerv4Reservation -ScopeId $p.ScopeId @common -ErrorAction SilentlyContinue | Where-Object { $_.ClientId -eq $p.ClientId }/nif ($existing) {/n  Remove-DhcpServerv4Reservation -ScopeId $p.ScopeId -ClientId $p.ClientId @common/n}/nAdd-DhcpServerv4Reservation -ScopeId $p.ScopeId -IPAddress $p.IPAddress -ClientId $p.ClientId -Name $p.Name @common/nforeach ($o in $p.Options) {/n  Set-DhcpServerv4OptionValue -ReservedIP $p.IPAddress -OptionId $o.Id -Value $o.Value @common/n}/nConvertTo-Json @{ ok = $true }/n"}
--- step
complete
--- hostctl
{"host": "ssh://admin@dhcp01:22?shell=powershell&pathname=windows&timeout=120", "password": false, "script": "$ErrorActionPreference = 'Stop'/n$p = ConvertFrom-Json '{/"ScopeId/": /"10.0.0.0/", /"ClientId/": /"aa-bb-cc-dd-ee-ff/", /"ComputerName/": /"dhcp01/"}'/n$common = @{}/nif ($p.ComputerName) { $common['ComputerName'] = $p.ComputerName }/n$existing = Get-DhcpServerv4Reservation -ScopeId $p.ScopeId @common -ErrorAction SilentlyContinue | Where-Object { $_.ClientId -eq $p.ClientId }/nif ($existing) {/n  Remove-DhcpServerv4Reservation -ScopeId $p.ScopeId -ClientId $p.ClientId @common/n}/nConvertTo-Json @{ ok = $true }/n"}
--- recipes
# netboot: create the DHCP policies for 'ipxe' once, as an admin
$scope = '10.0.0.0'
if (-not (Get-DhcpServerv4Class -Name 'iPXE' -Type User -ComputerName 'dhcp01' -ErrorAction SilentlyContinue)) { Add-DhcpServerv4Class -Name 'iPXE' -Type User -Data 'iPXE' -ComputerName 'dhcp01' }
Add-DhcpServerv4Policy -Name 'ipxe' -ScopeId $scope -Condition AND -UserClass EQ,'iPXE' -ComputerName 'dhcp01'
Set-DhcpServerv4OptionValue -PolicyName 'ipxe' -ScopeId $scope -OptionId 67 -Value 'boot.ipxe' -ComputerName 'dhcp01'
