How to Get Azure VM Details using PowerShell?

Find Azure VM Username (PowerShell)

Azure PowerShell command to find the VM admin username for both Windows and Linux Azure VMs:

cmd: Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty OSProfile

Azure PowerShell command to view the VM OS profile details:

cmd: Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty OSProfile | Select -ExpandProperty WindowsConfiguration

Get Azure VM Properties (PowerShell)

Get-AzVM command returns the Azure VM ResourceGroupName, VM Name, VM Location, VmSize, OsType, NIC, VM Provisioning State, Zone

cmd: Get-AzVM

Find all the Azure VM properties using PowerShell:

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_"

This command returns Azure VM ResourceGroupName, Id, VmId, Name, Type, Location, Tags, DiagnosticsProfile, Extensions, HardwareProfile, NetworkProfile, OSProfile, ProvisioningState, StorageProfile 

Get all the Azure VM Extentions Properties (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty Extensions

Get only the Name of Extentions of Azure VM (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty Extensions | Select Name

Get Azure VM Extensions Details (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty Extensions | Select -ExpandProperty Settings

Get Azure VM Size (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty HardwareProfile

Get Azure VM Storage Profile Details (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty StorageProfile

Get VM Diagnostics Profile Details (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty DiagnosticsProfile

Get Status of Azure VM (PowerShell)

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_"  -status

Get Azure Security Compliance Report (PowerShell)

Get-AzSecurityCompliance

Windows Azure VM Run Commands

Windows Run Command uses the VM agent to let you run a script inside the target virtual machine. This can be helpful for troubleshooting and recovery, and for general machine and application maintenance.

Note: In order to use Run Command the VM should be in running state.

Step 1: Login to Azure Portal and access the target Azure Virtual Machine in which you want to enable the run commands

Step 2: Navigate to Operations >> Run command >> Select your required command to execute

List of Azure VM Run Commands:

RunPowerShellScript: Executes a PowerShell script

DisableNLA: Disable Network Level Authentication

DisableWindowsUpdate: Disable Windows Update Automatic Updates

EnableAdminAccount: Enable administrator account

Checks if the local Administrator account is disabled, and if so enables it.

EnableEMS: Enable EMS

EnableRemotePS: Enable remote PowerShell

EnableWindowsUpdate: Enable Windows Update Automatic Updates

Enable Automatic Updates through Windows Update.

IPConfig: List IP configuration

Shows detailed information for the IP address, subnet mask and default gateway for each adapter bound to TCP/IP.

RDPSettings: Verify RDP Listener Settings

ResetRDPCert: Restore RDP Authentication mode to defaults

SetRDPPort: Set Remote Desktop port

Azure VM Run Commands

Use Az Rest cmdlets to find more details about the resources in Azure:

  • az rest command to get the properties of the all the provisioned resources with resource created time with in the subscription.

az rest \
--method GET \
--url "https://management.azure.com/subscriptions/{add_subscripion_id_here}/resources/" \
--url-parameters api-version=2020-06-01 \$expand=createdTime

  • az rest command to get the properties of the all the provisioned storage account resources with in the subscription.

az rest \
--method GET \
--url "https://management.azure.com/subscriptions/{add_subscripion_id_here}/providers/Microsoft.Storage/storageAccounts/" \
--url-parameters api-version=2021-09-01

List Azure Modules Name, Version, Exported Commands

Get Azure Modules List with Properties

  • cmd: get-module -list 
  • cmd: get-module -listavailable

Sample Output:

get-module -list

  • cmd: get-module -list |  select-object Name

Sample Output:

get-module -list |  select-object Name

  • cmd: get-module -list |  select-object Name,ExportedCommands

Sample Output:

get-module -list |  select-object Name,ExportedCommands


Check Azure AD Users Properties

Get the list of Azure AD Users

  • cmd: Get-AzADUser

returns all the properties of Azure AD

Get the Count of Azure AD Users

  • cmd: (Get-AzADUser).count

returns the count of Azure AD users.

Get the First 10 Azure AD Users

  • cmd: get-azaduser -first 10

returns DisplayName, Id, Mail, UserPrincipalName of first 10 from the list.

Get-AdUser Export To CSV File

  • cmd: Get-AzADUser | Export-CSV -Path TestUsers.csv