Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

Azure Virtual Machine disk status report using Powershell

Posted on August 17, 2019February 27, 2022

Update : updated script to support Azure Az powershell module.

Here is a powershell script to generate a report of Azure Managed VM disks in a subscription. It generates a csv file which includes Disk Size, SKU, and associated VM details.

All these information can be helpful when you are auditing your Azure environment and want to identify any big Premium unattached disk adding bills to your Azure consumption bill. Once you identify such unattached managed disk, as a next action item you would like to delete them. Refer to post on deleting unattached managed disk.

Before start using this script, make sure, you have Azure Az Module installed and imported on the system. For more information on how to install and configure Az module refer following article : https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-5.5.0

Let me know if this is helpful!

$currentDir = $(Get-Location).Path
$oFile = "$($currentDir)\AzureDisk_Details.csv"

if(Test-Path $oFile){Remove-Item $oFile -Force}

"ResourceGroupName,DiskName,AttachedVM,TimeCreated,OSType,DiskSizeInGB,DiskSKU,Encrypted,ProvisioningState,Location" | Out-File $oFile -Append -Encoding ASCII
Get-AzDisk | ForEach-Object{
	$rgName = $diskName = $timeCreated = $osType = $diskSize = $diskSku = $encrypted = $provState = $location = $managedBy = ""
	$rgName = $_.ResourceGroupName
	$diskName = $_.Name
	$managedBy = if($_.ManagedBy){$_.ManagedBy.split("/")[-1]}
	$timeCreated = $_.TimeCreated
	$osType = $_.OsType
	$diskSize = $_.DiskSizeGB
	$diskSku = (Get-AzDisk -Name $diskName -ResourceGroupName $rgName | select Sku -ExpandProperty Sku).Name
	$encrypted = $_.EncryptionSettings
	$provState = $_.ProvisioningState
	$location = $_.Location	
	"$rgName,$diskName,$managedBy,$timeCreated,$osType,$diskSize,$diskSku,$encrypted,$provState,$location" | Out-File $oFile -Append -Encoding ASCII
}

Download above script and save it with a .ps1 file extension. Open powershell console and, login to your Azure account using – Login-AzAccount. It will prompt you to enter your Azure credentials.

Login to Azure

After you login to Azure, run the powershell script saved in previous step.

Run powershell script

You will receive a csv file output like below:

CSV output with Azure disk information

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
July 2025
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes