Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

How to enable boot diagnostics on Azure VMs

·645 words·4 mins· 100 views · 5 likes ·
Azure CLI Azure Cloud Shell Azure PowerShell Connect-AzAccount

Hey, it’s Jorge. In this mini-post, I want to show you how to enable boot diagnostics on Azure virtual machines. This feature can be activated using the portal or command-line tools, but today, I will show you how to enable this debugging feature using PowerShell and Azure CLI. Enabling boot diagnostics will create a container in the desired storage account with the following name format.

bootdiagnostics + Virtual machine name + Virtual machine ID

You will find two blob pages inside the container, one BMP file from the latest VM screenshot, and a LOG file.

Prerequisites>

Prerequisites #

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You can use an existing Storage Account, or you can create a new one. If you want to know how to create a Storage Account using PowerShell, check out this  link.

Important: The Boot diagnostics feature does not support a premium storage account.

Azure PowerShell Workaround>

Azure PowerShell Workaround #

If you want to know how to install the PowerShell Azure module on your machine, check out this link. The simplest way to get started is to sign in interactively at the command line.

Connect-AzAccount

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Get-AzSubscription
Select-AzSubscription -Subscription "My Subscription"

Once you set your default subscription, you’re ready to start.

Set the variables>

Set the variables #

Here, we define the characteristics of our environment and the resource’s properties.

$resourceGroupName = "RG-DEMO-NE"
$storageAccountName = "stoaccountps"
$vmName = "VM-DEMO-NE"

The following command will store the VM in a variable to pass as a parameter in the next step.

$vm = Get-AzVM `
    -Name $vmName `
    -ResourceGroupName $resourceGroupName
Enable boot diagnostics>

Enable boot diagnostics #

To enable Boot diagnostics on your virtual machine, use the Set-AzVMBootDiagnostic** cmdlet with the following syntax.

Set-AzVMBootDiagnostic  `
    -VM $vm `
    -ResourceGroupName $resourceGroupName `
    -StorageAccountName $storageAccountName `
    -Enable

boot diagnostics
And then, you must use the Update-AzVM cmdlet to change takes effect.

Update-AzVM `
    -VM $vm `
    -ResourceGroupName $resourceGroupName

Update-AzVM

Get boot diagnostic data>

Get boot diagnostic data #

if you want to get boot diagnostic data from your virtual machine. You can use the Get-AzVMBootDiagnosticsData cmdlet to download the screenshot images to a local directory.

Get-AzVMBootDiagnosticsData `
    -Name $vmName `
    -ResourceGroupName $resourceGroupName `
    -Windows `
    -LocalPath "C:\Users\jorge\Downloads\bootdiagnostics"
Disable boot diagnostics>

Disable boot diagnostics #

To disable Boot diagnostics on your virtual machine, follow these steps:

Set-AzVMBootDiagnostic  `
    -VM $vm `
    -Disable

Update-AzVM `
    -VM $vm `
    -ResourceGroupName $resourceGroupName

Set-AzVMBootDiagnostic

Azure CLI Workaround>

Azure CLI Workaround #

In this case, we will use Azure Cloud Shell, a browser-based shell built into Azure Portal. This allows us to use the Azure command-line tools (Azure CLI and Azure PowerShell) directly from a browser. If you want to know more about Azure Cloud Shell, check out this link. First, we define the characteristics of our environment and store the values in variables.

resourceGroupName="RG-DEMO-NE"
stoaccountName="stoaccountcli"
vmName="VM-DEMO-NE"

To enable boot diagnostics with the Azure CLI, you must know the URL of the blob storage service.

blobService=$(az storage account show --name stoaccountcli --query 'primaryEndpoints.blob' --output tsv)
Enable boot diagnostics>

Enable boot diagnostics #

Once you have all the necessary information, you can enable the boot diagnostic feature with the following command.

az vm boot-diagnostics enable \
--name $vmName \
--resource-group $resourceGroupName \
--storage $blobService
Disable boot diagnostics>

Disable boot diagnostics #

If you need to disable this functionality to change the storage account or disable it, use the following command.

az vm boot-diagnostics disable \
--name $vmName \
--resource-group $resourceGroupName

Thanks for reading my post. I hope you find it useful.

For more information about other extensions of Azure Diagnostics, see this link.