Use PowerShell to Create an Azure VM report with nice look
This post is to simplify things on getting Azure classic VM report in a nice format. We wrote PowerShell script to collect azure VM information in HTML format.
https://2.bp.blogspot.com/-C9suhFOVoY4/VzjgG1nWs0I/AAAAAAAAAo8/LV4JlcqQIDgmqm2C9Ky3lUTU5F4UkGHzwCLcB/s400/Capture.JPG
You can download the script from here:
Make sure you have Azure PowerShell module installed.
1. To check the module
- Login to Azure classic subscription.
Run
Add-AzureAccount
You will be shown login windows. Provide your credentials
https://1.bp.blogspot.com/-_7icwlHbZPM/VzjdVpC3JAI/AAAAAAAAAoc/x0SV_FxFCcstQbjvCTJ7gXvpAN2QrjhZACLcB/s320/Capture1.JPG
You will see your Azure subscription ID and tenants ID.
https://2.bp.blogspot.com/-Pf73MgG1kbY/VzjeE1Nu3mI/AAAAAAAAAok/gyUZPClgVgscve5zAI_V-AYuMjmYxU5tQCLcB/s640/Pic2.png
3. Select-AzureSubscription -SubscriptionName 'your sub. name.
https://4.bp.blogspot.com/-caecaWk7i0g/VzjeXOCxLII/AAAAAAAAAoo/BUY8cBOgpTwli5aB_28ma6-ZgqRC12OOQCLcB/s640/Pic3.png
4. Before extracting VM report you will have to know the name of your cloud service. Check your cloud service you want to take VM report from.
https://3.bp.blogspot.com/-K0U5PmK8k4o/Vzjel3CRzcI/AAAAAAAAAos/_2oENphtDVkBxmAx1Xl_C0BtAINQzzeEgCLcB/s640/Pic4.png
5. CCreate folder structure “C:\temp\Reports\Azure_VM_Info” in this location where you will save your report.
6. Change your cloud service name and run your PowerShell command to get the nice report.
$cloudsname = 'Your azure cloud service name'
$getvm = Get-AzureVM -ServiceName $cloudsname | select -Property Name,IpAddress,InstanceSize,Status | ConvertTo-Html -Fragment
$getvm = $getvm | foreach {
$_ -replace "<td>ReadyRole</td>","<td style='color:green'>Running</td>"
}
$getvm = $getvm | foreach {
$_ -replace "<td>StoppedDeallocated</td>","<td style='color:red'>Stopped</td>"
}
$date = Get-Date -UFormat "%m-%d-%y"
$filename = "AzureVM_Info"+"$date"
$HTML = ConvertTo-Html -Body "<H2> AzureVMInfo - </H2>", "$getvm" -Head "<style> body {background-color: lightblue; } table {background-color: white; margin 5px; float: left; top: 0px; display: inline-block; padding: 5px; border: 1px solid black} tr:nth-child(odd) {background-color: lightgray} </style>"
$HTML | Out-File C:\temp\Reports\Azure_VM_Info\$filename.html
Invoke-Item C:\temp\Reports\Azure_VM_Info\$filename.html
Hope this post will be informative to you.
Download Link
You can download the script from here:
Get-Module -ListAvailable
You should be able to see Azure module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.2.3 Azure {Disable-AzureServiceProjectRemoteDesktop, Enable-AzureServiceProjectRemoteDesktop, Get-AzureServiceProjectRoleRuntime, Save-AzureServiceProject...
- Login to Azure classic subscription.