Hi Varma,
Please see the following script:
# Get All Subscriptions
$subs = Get-AzureRmSubscription
# Array to store list of VMs
$VMReport = @()
# Loop through each subscription
foreach ($sub in $subs) {
# Display the current processing subscription
Write-Host "Processing subscription $($sub.Name)"
try {
# Select the subscription
# Add conditions here if you want to skip a particular subscription
Select-AzureRmSubscription -SubscriptionId $sub.SubscriptionId -ErrorAction Continue
# Get all the VMs information
$vms = Get-AzureRmVm
# Loop through all the VMs
foreach ($vm in $vms) {
Write-Host "$($vm.Name) $($vm.ResourceGroupName) $($vm.HardwareProfile.VmSize) $($vm.OsType) $($vm.ProvisioningState) $($vm.Location) $($vm.StorageProfile.OsDisk.Name)"
# Create a new object and add it to the VMReport array
$VMReport += New-Object psobject -Property @{
"SubName" = $sub.Name
"VMName" = $vm.Name
"VMSize" = $vm.HardwareProfile.VmSize
"VMOSType" = $vm.OsType
"VMProvisioningState" = $vm.ProvisioningState
"VMLocation" = $vm.Location
"VMOSDisk" = $vm.StorageProfile.OsDisk.Name
}
}
}
catch {
Write-Host "Error processing subscription $($sub.Name): $_"
}
}
# Export to CSV format
$VMReport | Export-Csv "report.csv" -NoTypeInformation
If this is helpful please accept answer.