Skip to content

Get-VMReport

Azure: Gets a report of virtual machines

param(
	[Parameter(Mandatory = $false)]
	[string]$ResourceGroupName
)

try {
	Import-Module Az.Compute -ErrorAction Stop
	
	[hashtable]$cmdArgs = @{ 'ErrorAction' = 'Stop' }
	if ($ResourceGroupName) { $cmdArgs.Add('ResourceGroupName', $ResourceGroupName) }

	$vms = Get-AzVM @cmdArgs | Select-Object Name, ResourceGroupName, Location, ProvisioningState, @{N='PowerState'; E={(Get-AzVM -ResourceGroupName $_.ResourceGroupName -Name $_.Name -Status).Statuses[1].DisplayStatus}}
	Write-Output $vms
} catch {
	Write-Error $_
	exit 1
}

The name of the resource group (optional).

An interactive directory of PowerShell scripts.