Skip to content
Related Articles
Open in App
Not now

Related Articles

Microsoft Azure – Fetch License Details of Azure Servers

Improve Article
Save Article
Like Article
  • Last Updated : 21 Mar, 2022
Improve Article
Save Article
Like Article

In this article, we’ll fetch the details of all Azure Virtual Machine License Details within the Subscription using the Azure PowerShell Module Script. What we can achieve with the script? We will fetch of details of Azure VM which has License and also we also fetch the details like where Azure VM without any License or License not activated. The Script we execute will all store the Server’s information in a CSV file.

This script will help in finding the list of Servers where the License is not activated and further helps to remediate.

Implementation :

Follow the below steps to fetch license details of Azure servers:

Step 1: Log in to Azure.

Step 2: Access the cloud shell from the azure portal and select PowerShell

Step 3: Create a new file using the touch filename.ps1

touch vmlicense-script.ps1

Step 4: Use the following command to code in the created file

code ./vmlicense-script.ps1
  • Copy and Paste the following code into the file and save the file.

Azure PowerShell Script:

$Data = @()
$Subscription="Add Subscription Name Here"
Set-AzureRmContext -SubscriptionName "$Subscription" | Out-Null
$RGs = Get-AzureRMResourceGroup

foreach ($RG in $RGs) {
    $VMs = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName
    foreach($VM in $VMs) {
        if (!$VM.LicenseType) {
            $LicenseType = "No_License"
        else {
                $LicenseType = $VM.LicenseType 

        $VMCustom = New-Object System.Object
        $VMCustom | Add-Member -Type NoteProperty -Name VMName -Value $VM.Name
        $VMCustom | Add-Member -Type NoteProperty -Name Subscription -Value $Subscription
        $VMCustom | Add-Member -Type NoteProperty -Name RGNAME -Value $VM.ResourceGroupName
        $VMCustom | Add-Member -Type NoteProperty -Name Location -Value $VM.Location
        $VMCustom | Add-Member -Type NoteProperty -Name OSType -Value $VM.StorageProfile.OSDisk.OSType
        $VMCustom | Add-Member -Type NoteProperty -Name LicenseType -Value $LicenseType

        $Data += $VMCustom

$Data | Export-CSV "./VMlicense.csv" -Delimiter ";" -NoTypeInformation

Note: Add/Update Your Subscription Name in Line 2.

Step 5: To execute the file run the following command


Then the output looks like the following:

Sample 1:


Sample 2:


  • To get the CSV – Click on Upload/Download File from PowerShell Terminal beside Settings Option >> Select Download.


  • You will get a pop up >> add /VMlicense.csv and Click on Download


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!