@@ -17,6 +17,8 @@ function New-OpenShiftVM {
1717 $NumCpu ,
1818 $ReferenceSnapshot ,
1919 $ResourcePool ,
20+ $SecureBoot ,
21+ $StoragePolicy ,
2022 [Parameter (Mandatory = $true )]
2123 $Tag ,
2224 [Parameter (Mandatory = $true )]
@@ -35,6 +37,7 @@ function New-OpenShiftVM {
3537 $args.Remove (' Network' ) > $null
3638 $args.Remove (' MemoryMB' ) > $null
3739 $args.Remove (' NumCpu' ) > $null
40+ $args.Remove (' SecureBoot' ) > $null
3841 foreach ($key in $args.Keys ){
3942 if ($NULL -eq $ ($args.Item ($key )) -or $ ($args.Item ($key )) -eq " " ) {
4043 $args.Remove ($key ) > $null
@@ -76,6 +79,12 @@ function New-OpenShiftVM {
7679 New-AdvancedSetting - Entity $vm - name " guestinfo.afterburn.initrd.network-kargs" - value $kargs - Confirm:$false - Force > $null
7780 }
7881
82+ # Enable secure boot if needed
83+ if ($true -eq $SecureBoot )
84+ {
85+ Set-SecureBoot - VM $vm
86+ }
87+
7988 return $vm
8089}
8190
@@ -289,7 +298,7 @@ function New-OpenshiftVMs {
289298
290299 # Clone the virtual machine from the imported template
291300 # $vm = New-OpenShiftVM -Template $template -Name $name -ResourcePool $rp -Datastore $datastoreInfo -Location $folder -LinkedClone -ReferenceSnapshot $snapshot -IgnitionData $ignition -Tag $tag -Networking $network -NumCPU $numCPU -MemoryMB $memory
292- $vm = New-OpenShiftVM - Template $template - Name $name - ResourcePool $rp - Datastore $datastoreInfo - Location $folder - IgnitionData $ignition - Tag $tag - Networking $network - Network $node.network - NumCPU $numCPU - MemoryMB $memory
301+ $vm = New-OpenShiftVM - Template $template - Name $name - ResourcePool $rp - Datastore $datastoreInfo - Location $folder - IgnitionData $ignition - Tag $tag - Networking $network - Network $node.network - SecureBoot $secureboot - StoragePolicy $storagepolicy - NumCPU $numCPU - MemoryMB $memory
293302
294303 # Assign tag so we can later clean up
295304 # New-TagAssignment -Entity $vm -Tag $tag
@@ -321,4 +330,21 @@ function New-OpenshiftVMs {
321330 foreach ($job in $jobs ) {
322331 Receive-Job - Job $job
323332 }
333+ }
334+
335+ # This function is used to set secure boot.
336+ function Set-SecureBoot {
337+ param (
338+ $VM
339+ )
340+
341+ $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
342+ $spec.Firmware = [VMware.Vim.GuestOsDescriptorFirmwareType ]::efi
343+
344+ $boot = New-Object VMware.Vim.VirtualMachineBootOptions
345+ $boot.EfiSecureBootEnabled = $true
346+
347+ $spec.BootOptions = $boot
348+
349+ $VM.ExtensionData.ReconfigVM ($spec )
324350}
0 commit comments