Quickstart: Create an Azure portal dashboard with PowerShell
A dashboard in the Azure portal is a focused and organized view of your cloud resources. This article focuses on the process of using the Az.Portal PowerShell module to create a dashboard. The dashboard shows the performance of a virtual machine (VM) that you create, as well as some static information and links.
A dashboard in the Azure portal is a focused and organized view of your cloud resources. This quickstart shows how to use the Az.Portal PowerShell to create a dashboard. The example dashboard shows the performance of a virtual machine (VM), along with some static information and links.
Prerequisites
An Azure account with an active subscription. Create a trial subscription.
If you choose to use PowerShell locally, this article requires that you install the Az PowerShell module and connect to your Azure account using the Connect-AzAccount -Environment AzureChinaCloud cmdlet. For more information about installing the Az PowerShell module, see Install Azure PowerShell.
Note
Before you can use Azure CLI in Microsoft Azure operated by 21Vianet, please run az cloud set -n AzureChinaCloud
first to change the cloud environment. If you want to switch back to Azure Public Cloud, run az cloud set -n AzureCloud
again.
Choose a specific Azure subscription
If you have multiple Azure subscriptions, choose the appropriate subscription in which the resources should be billed. Select a specific subscription using the Set-AzContext cmdlet.
Set-AzContext -SubscriptionId 00000000-0000-0000-0000-000000000000
Define variables
The example dashboard uses several pieces of information repeatedly. Create variables to store this information.
# Name of resource group used throughout this article
$resourceGroupName = 'myResourceGroup'
# Azure region
$location = 'chinaeast'
# Dashboard Title
$dashboardTitle = 'Simple VM Dashboard'
# Dashboard Name
$dashboardName = $dashboardTitle -replace '\s'
# Your Azure Subscription ID
$subscriptionID = (Get-AzContext).Subscription.Id
# Name of test VM
$vmName = 'myVM1'
Create a resource group
Create an Azure resource group using the New-AzResourceGroup cmdlet. A resource group is a logical container in which Azure resources are deployed and managed as a group.
The following example creates a resource group based on the name in the $resourceGroupName
variable in the region specified in the $location
variable.
New-AzResourceGroup -Name $resourceGroupName -Location $location
Create a virtual machine
The example dashboard requires an existing VM. Create a VM by following these steps.
Store login credentials for the VM in a variable. The password must be complex. This is a new username and password (not the account you use to sign in to Azure). For more information, see username requirements and password requirements.
$Cred = Get-Credential
Create the VM.
$AzVmParams = @{
ResourceGroupName = $resourceGroupName
Name = $vmName
Location = $location
Credential = $Cred
}
New-AzVm @AzVmParams
The VM deployment now starts and typically takes a few minutes to complete. After deployment completes, move on to the next section.
Download the dashboard template
Since Azure dashboards are resources, they can be represented as JSON. The following code downloads a JSON representation of a sample dashboard. For more information, see The structure of Azure Dashboards.
$myPortalDashboardTemplateUrl = 'https://raw.githubusercontent.com/Azure-Samples/azure-docs-powershell-samples/refs/heads/main/azure-portal/portal-dashboard-template-testvm.json'
$myPortalDashboardTemplatePath = "$HOME\portal-dashboard-template-testvm.json"
Invoke-WebRequest -Uri $myPortalDashboardTemplateUrl -OutFile $myPortalDashboardTemplatePath -UseBasicParsing
Customize the template
Customize the downloaded template by running the following code.
$Content = Get-Content -Path $myPortalDashboardTemplatePath -Raw
$Content = $Content -replace '<subscriptionID>', $subscriptionID
$Content = $Content -replace '<rgName>', $resourceGroupName
$Content = $Content -replace '<vmName>', $vmName
$Content = $Content -replace '<dashboardTitle>', $dashboardTitle
$Content = $Content -replace '<location>', $location
$Content | Out-File -FilePath $myPortalDashboardTemplatePath -Force
For more information about the dashboard template structure, see Microsoft portal dashboards template reference.
Deploy the dashboard template
You can use the New-AzPortalDashboard
cmdlet that's part of the Az.Portal module to deploy the template directly from PowerShell.
$DashboardParams = @{
DashboardPath = $myPortalDashboardTemplatePath
ResourceGroupName = $resourceGroupName
DashboardName = $dashboardName
}
New-AzPortalDashboard @DashboardParams
Review the deployed resources
Check that the dashboard was created successfully.
Get-AzPortalDashboard -Name $dashboardName -ResourceGroupName $resourceGroupName
Verify that you can see data about your virtual machine in the Azure portal dashboard.
In the Azure portal menu, select Dashboard.
On the dashboard page, select Simple VM Dashboard.
Review the dashboard, which should look similar to the one shown here. While some of the content is static, there are also charts that show the performance of the VM you created at the beginning.
Clean up resources
To remove the VM and associated dashboard, delete the resource group that contains them.
Caution
Deleting the resource group will delete all of the resources contained within it. If the resource group contains additional resources aside from your virtual machine and dashboard, those resources will also be deleted.
Remove-AzResourceGroup -Name $resourceGroupName
Remove-Item -Path "$HOME\portal-dashboard-template-testvm.json"
Next steps
For more information about the cmdlets contained in the Az.Portal PowerShell module, see: