Hello @Bhavishka Sathawane ,
Please use below powershell script, read out the comments for each line so that you can understand :
//Get All Subscriptions
$subs = Get-AzureRmSubscription
//Arry to store list of VMs
$vmobjs = @()
//loop through each subscription
foreach ($sub in $subs)
{
//Display the current processing subscription
Write-Host "Processing subscription $($sub.Name)"
try
{
//Select the subscription
//please add the condition 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
$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[0]
}
}
//export to csv format
$VMReport | Export-Csv "report.csv"