다음을 통해 공유


how to export VM details in Azure Resource Manager (ARM)

1. Run the following PowerShell script.

 
$cred = Get-Credential
(Login-AzureRmAccount -Credential $cred)>0
$Subscriptions = Get-AzureRMSubscription
$vmarray = @()
 $i=0
foreach ( $Subscription in $Subscriptions ) {
$SubscriptionId = $Subscription.SubscriptionId
(Login-AzureRmAccount -Credential $cred -subscriptionid $SubscriptionId)>0
(Select-AzureRMSubscription -SubscriptionId $SubscriptionId)>0
 $i++
 Write-Progress -activity $subscription.SubscriptionName -PercentComplete ($i/$Subscriptions.Count*100)
 ($rmvms=Get-AzurermVM) > 0
 foreach ($vm in $rmvms)
 {
 
 $vmstatus = Get-AzurermVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName -Status
 Get-AzurermVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName -Status
 
 $vmarray += New-Object PSObject -Property @{`
 Subscription=$Subscription.SubscriptionName; `
 AzureMode="Resource_Manager"; `
 Name=$vm.Name; PowerState=(get-culture).TextInfo.ToTitleCase(($vmstatus.statuses)[1].code.split("/")[1]); `
 Size=$vm.HardwareProfile.VmSize;
 ImageSKU=$vm.StorageProfile.ImageReference.Sku;
 OSType=$vm.StorageProfile.OsDisk.OsType;
 DiskSizeGB=$vm.StorageProfile.OsDisk.DiskSizeGB}
 }
}
# Gridview output

 $vmarray | Out-Gridview

And the output would look like the following image. Enjoy.

VMdetails1