Search code examples
azurepowershellvirtual-machineuefi

Is it possible to make UEFI settings ON/OFF using PowerShell command in a virtual machine?


I want to create a Virtual Machine in Azure with security Type as Trusted Launch where security profile has UEFI settings like SecureBoot and vTPM enabled.

Now, Once VM is deployed I want to turn off the UEFI settings, and Vice Versa using PowerShell command. Is it possible?


Solution

  • You can make use of below Az PowerShell commands to turn UEFI settings ON in Azure virtual machine.

    $VM = Get-AzVM -ResourceGroupName "rg_name" -VMName "vm_name"  
    Set-AzVMUefi -VM $VM -EnableVtpm $true -EnableSecureBoot $true
    Update-AzVM -VM $VM -ResourceGroupName "rg_name"
    

    While creating virtual machine, these settings will be enabled by default like below:

    enter image description here

    To turn above UEFI settings OFF in Azure virtual machine, you can make use of below Az PowerShell command by including $false in it like this:

    $VM = Get-AzVM -ResourceGroupName "rg_name" -VMName "vm_name"  
    Set-AzVMUefi -VM $VM -EnableVtpm $false -EnableSecureBoot $false
    Update-AzVM -VM $VM -ResourceGroupName "rg_name"
    

    Response:

    enter image description here

    When I checked the same in Portal, settings are disabled successfully like below:

    enter image description here

    Reference:

    Set-AzVMUefi (Az.Compute) | Microsoft