Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Warning
The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.
Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.
By default each Azure PowerShell cmdlet has predefined formatting of output making it easy to read. PowerShell also provides the flexibility to adjust the output or convert the cmdlet output to a different format with the following cmdlets:
Formatting | Conversion |
---|---|
Format-Custom | ConvertTo-Csv |
Format-List | ConvertTo-Html |
Format-Table | ConvertTo-Json |
Format-Wide | ConvertTo-Xml |
Format examples
In this example, we get a list of Azure VMs in our default subscription. The Get-AzureRmVM
command
defaults output into a table format.
Get-AzureRmVM
ResourceGroupName Name Location VmSize OsType NIC ProvisioningState
----------------- ---- -------- ------ ------ --- -----------------
MYWESTEURG MyUnbuntu1610 westeurope Standard_DS1_v2 Linux myunbuntu1610980 Succeeded
MYWESTEURG MyWin2016VM westeurope Standard_DS1_v2 Windows mywin2016vm880 Succeeded
If you would like to limit the columns returned you can use the Format-Table
cmdlet. In the
following example, we get the same list of virtual machines but restrict the output to just the name
of the VM, the resource group, and the location of the VM. The -Autosize
parameter sizes the
columns according to the size of the data.
Get-AzureRmVM |
Format-Table -Property Name, ResourceGroupName, Location -AutoSize
Name ResourceGroupName Location
---- ----------------- --------
MyUnbuntu1610 MYWESTEURG westeurope
MyWin2016VM MYWESTEURG westeurope
Output can also be formatted into a list. The following example shows this using theFormat-List
cmdlet.
Get-AzureRmVM |
Format-List -Property Name, VmId, Location, ResourceGroupName
Name : MyUnbuntu1610
VmId : 33422f9b-e339-4704-bad8-dbe094585496
Location : westeurope
ResourceGroupName : MYWESTEURG
Name : MyWin2016VM
VmId : 4650c755-fc2b-4fc7-a5bc-298d5c00808f
Location : westeurope
ResourceGroupName : MYWESTEURG
Convert to other data types
PowerShell also allows taking command output and converting it into multiple data formats. In the
following example, the Select-Object
cmdlet is used to get attributes of the virtual machines in
our subscription and convert the output to CSV format for easy import into a database or
spreadsheet.
Get-AzureRmVM |
Select-Object -Property ResourceGroupName, Id, VmId, Name, Location, ProvisioningState |
ConvertTo-Csv -NoTypeInformation
"ResourceGroupName","Id","VmId","Name","Location","ProvisioningState"
"MYWESTUERG","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYWESTUERG/providers/Microsoft.Compute/virtualMachines/MyUnbuntu1610","33422f9b-e339-4704-bad8-dbe094585496","MyUnbuntu1610","westeurope","Succeeded"
"MYWESTUERG","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYWESTUERG/providers/Microsoft.Compute/virtualMachines/MyWin2016VM","4650c755-fc2b-4fc7-a5bc-298d5c00808f","MyWin2016VM","westeurope","Succeeded"
Output can also be converted into the JSON format. The following example creates the same list of VMs but changes the output format to JSON.
Get-AzureRmVM |
Select-Object -Property ResourceGroupName, Id, VmId, Name, Location, ProvisioningState |
ConvertTo-Json
[
{
"ResourceGroupName": "MYWESTEURG",
"Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYWESTEURG/providers/Microsoft.Compute/virtualMachines/MyUnbuntu1610",
"VmId": "33422f9b-e339-4704-bad8-dbe094585496",
"Name": "MyUnbuntu1610",
"Location": "westeurope",
"ProvisioningState": "Succeeded"
},
{
"ResourceGroupName": "MYWESTEURG",
"Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYWESTEURG/providers/Microsoft.Compute/virtualMachines/MyWin2016VM",
"VmId": "4650c755-fc2b-4fc7-a5bc-298d5c00808f",
"Name": "MyWin2016VM",
"Location": "westeurope",
"ProvisioningState": "Succeeded"
}
]