![]() |
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
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 $VMCustom $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 ./vmlicense-script.ps1 Then the output looks like the following: Sample 1: ![]()
Sample 2: ![]()
![]()
![]()
|
Reffered: https://www.geeksforgeeks.org
DevOps |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |