First login to the Azure Account using:
Login-AzureRMAccount
The above command pops-up a window for the user credentials.
If there are multiple subscriptions hosted under the same account, use the Select-AzureRMSubscription cmdlet to select the respective subscription.
Select-AzureRmSubscription -SubscriptionId “XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX”
Get the Azure resources using the cmdlet Select-AzureRMResources
Get-AzureRmResource
To export the output in the CSV format, use the below command:
Get-AzureRmResource | ConvertTo-Html -Property ResourceGroupName, Name, Location, ResourceType
To export the output in the HTML format, use the below command
Get-AzureRmResource | ConvertTo-Html -Property ResourceGroupName, Name, Location, ResourceType
To export the output in the HTML format with tables use the below code:
$table = “<style>”
$table = $table + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$table = $table + “TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background: #dddddd;}”
$table = $table + “TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}”
$table = $table + “</style>”
Get-AzureRmResource | ConvertTo-Html -Property ResourceGroupName, Name, Location, ResourceType -Head $table | Out-File -FilePath “C:\Users\dhasign\Desktop\testpath.htm”
The Complete Script is as follows:
$table = “<style>”
$table = $table + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$table = $table + “TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background: #dddddd;}”
$table = $table + “TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}”
$table = $table + “</style>”
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId “XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX”
Get-AzureRmResource | ConvertTo-Html -Property ResourceGroupName, Name, Location, ResourceType -Head $table | Out-File -FilePath “C:\Users\dhasign\Desktop\testpath.htm”
Invoke-Expression “C:\Users\dhasign\Desktop\ testpath.htm”