Automation

 View Only
  • 1.  BIOS Boot option while creating VM

    Posted Mar 16, 2022 04:39 PM

    I'm a newbie to PowerCLI and I'm really interested to learn it.

    So I started with the UseCase, to create a VM. Is there any chance to give the "New-VM" a use BIOS instead of EFI Parameter?

     

    #Create New VM
    New-VM -Name $vmname -VMhost esx03.mydomain -Datastore esx03-local02 -NumCpu $cpuamount -MemoryGB $ramamount -DiskGB $hddamount -DiskStorageFormat Thin -NetworkName "VM Network" -CD -GuestId $guestid -Location Testing -ErrorAction Stop | Out-Null
     
    # Use VMXNET3
    Get-VM $vmname | Get-NetworkAdapter | Set-NetworkAdapter -Type VMXNet3 -Confirm:$False -ErrorAction Stop | Out-Null
     
    #Poweron VM
    Start-VM -VM $vmname -Confirm:$false -ErrorAction Stop | Out-Null
     
     #Mount ISO
    Get-VM -Name $vmname | Get-CDDrive| Set-CDDrive -Connected $true -IsoPath '[esx03-local01] ISOs/Windows Server 2019.iso' -Confirm:$False -ErrorAction Stop | Out-Null
     
    Thanks in advance.


  • 2.  RE: BIOS Boot option while creating VM

    Posted Mar 16, 2022 05:25 PM

    Not with a cmdlet afaik.
    But you can use the API method.
    Something like this for example



  • 3.  RE: BIOS Boot option while creating VM

    Posted Mar 17, 2022 10:46 AM

    Because of my rookie skills, I have to ask. How can I implement the API method to the code which I recently posted?



  • 4.  RE: BIOS Boot option while creating VM

    Posted Mar 17, 2022 11:29 AM
    When I put the Code into my 
     
    New-VM -Name $vmname -VMhost esx03.irgnet.wtf -Datastore esx03-local02 -NumCpu $cpuamount -MemoryGB $ramamount -DiskGB $hddamount -DiskStorageFormat Thin -NetworkName "VM Network" -CD -GuestId $guestid -Location Testing -ErrorAction Stop | Out-Null # Changes on Datastore to my own
        Get-VM $vmname | Get-NetworkAdapter | Set-NetworkAdapter -Type VMXNet3 -Confirm:$False -ErrorAction Stop | Out-Null
        $vm = Get-VM $vmname

        $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
        $spec.Firmware = [VMware.Vim.GuestOsDescriptorFirmwareType]::bios
        $vm.ExtensionData.ReconfigVM($spec)
        Start-VM -VM $vmname -Confirm:$false -ErrorAction Stop | Out-Null
        Get-VM -Name $vmname | Get-CDDrive| Set-CDDrive -Connected $true -IsoPath '[esx03-local01] ISOs/Windows Server 2019.iso' -Confirm:$False -ErrorAction Stop | Out-Null
        Write-Host "Successfully created $($vmname)" -ForegroundColor Green
     
    I get following warning: "Invalid virtual machine configuration. EFI secure boot could be enabled only on EFI firmware."


  • 5.  RE: BIOS Boot option while creating VM

    Posted Mar 17, 2022 11:34 AM

    Are the prerequisites mentioned in Enable or Disable UEFI Secure Boot for a Virtual Machine fulfilled for that VM?



  • 6.  RE: BIOS Boot option while creating VM

    Posted Sep 23, 2022 03:42 PM

    When creating a new VM with GuestID windows9Server64Guest on vSphere 7, the VM will be configured to use EFI and Secure Boot.

    Your code example changes the firmware from EFI to BIOS but doesn't disable Secure Boot. That's why you are getting that error.

    Add the bootOptions.EfiSecureBootEnabled option to your spec to also disable Secure Boot:

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $spec.Firmware = [VMware.Vim.GuestOsDescriptorFirmwareType]::bios
    $spec.bootOptions.EfiSecureBootEnabled = $false
    $vm.ExtensionData.ReconfigVM($spec)

     



  • 7.  RE: BIOS Boot option while creating VM

    Posted Feb 20, 2023 05:17 PM

    I would like to query (get, not set) the Secure Boot setting. How do I do that?



  • 8.  RE: BIOS Boot option while creating VM

    Posted Feb 20, 2023 05:27 PM

    Try like this



  • 9.  RE: BIOS Boot option while creating VM

    Posted Feb 20, 2023 05:59 PM

    Thanks for that. The syntax is complex. Drilling deep into settings requires much more understanding of the finicky details of the API than I've got!

    I did find this: https://github.com/vmware/PowerCLI-Example-Scripts/blob/master/Scripts/SecureBoot.ps1

    But I couldn't master the query for ALL VMs like you've so handily provided LucD!



  • 10.  RE: BIOS Boot option while creating VM

    Posted Feb 20, 2023 06:22 PM

    If you want to go beyond what the cmdlets offer, you will have to dive into the API Reference and learn your way around in there I'm afraid.
    That is not light reading and might take some time to get used to.
    On the other hand, the fact it is quite easy with PS/PowerCLI is an advantage.