Azure Compute PowerShell Cmdlets
This section provides comprehensive documentation for Azure Compute PowerShell cmdlets. These cmdlets allow you to manage virtual machines, scale sets, disks, and other compute resources in Azure.
Compute Resources
Manage your virtual machines and related resources.
Get-AzVM
Gets one or more virtual machines.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual machine. | System.String | No |
| -Status | Gets the status of the virtual machine. | System.Management.Automation.SwitchParameter | No |
Example
# Get all virtual machines in a resource group
Get-AzVM -ResourceGroupName "myResourceGroup"
# Get a specific virtual machine and its status
Get-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM" -Status
New-AzVM
Creates a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual machine. | System.String | Yes |
| -Location | The location of the virtual machine. | System.String | Yes |
| -ImageName | The name of the OS image to use. | System.String | Yes |
| -Credential | The credentials for the virtual machine. | System.Management.Automation.PSCredential | No |
Example
New-AzVM -ResourceGroupName "myResourceGroup" -Name "myNewVM" -Location "East US" -ImageName "UbuntuLTS" -Credential (Get-Credential)
Set-AzVM
Modifies a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -VirtualMachine | The virtual machine object. | Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine | Yes |
| -Size | The VM size. | System.String | No |
Example
$vm = Get-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM"
$vm.HardwareProfile.VmSize = "Standard_D2s_v3"
Set-AzVM -VirtualMachine $vm
Remove-AzVM
Deletes a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual machine. | System.String | Yes |
| -Force | Suppresses confirmation. | System.Management.Automation.SwitchParameter | No |
Example
Remove-AzVM -ResourceGroupName "myResourceGroup" -Name "myVMToDelete" -Force
Start-AzVM
Starts a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual machine. | System.String | Yes |
Example
Start-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM"
Stop-AzVM
Stops a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual machine. | System.String | Yes |
| -Force | Suppresses confirmation. | System.Management.Automation.SwitchParameter | No |
Example
Stop-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM" -Force
Restart-AzVM
Restarts a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual machine. | System.String | Yes |
Example
Restart-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM"
Invoke-AzVMRunCommand
Runs a script within a virtual machine.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -VMName | The name of the virtual machine. | System.String | Yes |
| -CommandId | The ID of the command to run. | System.String | Yes |
| -Parameter | Parameters for the command. | System.String[] | No |
Example
Invoke-AzVMRunCommand -ResourceGroupName "myResourceGroup" -VMName "myVM" -CommandId "RunPowerShellScript" -Parameter @{ "script" = "Get-Process" }
Storage Cmdlets
Manage Azure Storage accounts.
Get-AzStorageAccount
Gets one or more Azure Storage accounts.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the storage account. | System.String | No |
Example
Get-AzStorageAccount -ResourceGroupName "myStorageRG"
New-AzStorageAccount
Creates a storage account.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the storage account. | System.String | Yes |
| -Location | The location of the storage account. | System.String | Yes |
| -SkuName | The SKU name for the storage account. | Microsoft.Azure.Commands.Management.Storage.Models.StorageAccountSkuName | Yes |
Example
New-AzStorageAccount -ResourceGroupName "myStorageRG" -Name "mystorageaccount123" -Location "West US" -SkuName "Standard_LRS"
Networking Cmdlets
Manage Azure Virtual Networks.
Get-AzVirtualNetwork
Gets one or more virtual networks.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual network. | System.String | No |
Example
Get-AzVirtualNetwork -ResourceGroupName "myNetworkRG"
New-AzVirtualNetwork
Creates a virtual network.
Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| -ResourceGroupName | The name of the resource group. | System.String | Yes |
| -Name | The name of the virtual network. | System.String | Yes |
| -Location | The location of the virtual network. | System.String | Yes |
| -AddressPrefix | The address prefix for the virtual network. | System.String[] | Yes |
Example
New-AzVirtualNetwork -ResourceGroupName "myNetworkRG" -Name "myVNet" -Location "East US" -AddressPrefix "10.0.0.0/16"