Module Description

The Az.Compute PowerShell module provides a set of cmdlets for managing Azure Compute resources. This module enables you to deploy, configure, and manage virtual machines, virtual machine scale sets, availability sets, and other compute-related services within your Azure environment.

Leverage the power of PowerShell to automate complex deployment scenarios, streamline resource management, and integrate compute operations into your DevOps workflows.

Current Version: 6.2.0 Last Updated: 2023-10-27

Installation

To install the Az.Compute module, open an elevated PowerShell session and run the following command:

Install-Module -Name Az.Compute -Scope CurrentUser -Repository PSGallery -Force

You might need to accept the NuGet provider and the module installation. For more details on installing the Azure PowerShell Az module, please refer to the official documentation.

Key Cmdlets

The Az.Compute module offers a comprehensive set of cmdlets for managing Azure compute resources. Here are some of the most commonly used ones:

  • Get-AzVM: Retrieves information about virtual machines.
  • New-AzVM: Creates a new virtual machine.
  • Update-AzVM: Updates an existing virtual machine.
  • Remove-AzVM: Deletes a virtual machine.
  • Get-AzVMSS: Retrieves information about virtual machine scale sets.
  • New-AzVMSS: Creates a new virtual machine scale set.
  • Add-AzVmdScaleSetExtension: Adds an extension to a virtual machine scale set.
  • Get-AzAvailabilitySet: Retrieves information about availability sets.
  • New-AzImageConfig: Creates a configuration object for a custom image.
  • New-AzImage: Creates a custom image from a virtual machine.

Usage Examples

Here are a few examples demonstrating how to use the Az.Compute cmdlets:

Example 1: Listing all Virtual Machines

Get-AzVM -ResourceGroupName "MyResourceGroup"

Example 2: Creating a new Virtual Machine


# Define VM configuration
$vmConfig = New-AzVMConfig -VMName "MyVM" -VMSize "Standard_DS1_v2"
$vmConfig = Set-AzVMOperatingSystem -VM $vmConfig -Linux -ComputerName "MyLinuxVM" -Credential (Get-Credential)
$vmConfig = Add-AzVMNetworkInterface -VM $vmConfig -Name "MyNic" -StaticVNetIPAddress "10.0.0.4" -SubnetId "/subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVNet/subnets/MySubnet"

# Create the VM
New-AzVM -ResourceGroupName "MyResourceGroup" -Location "East US" -VM $vmConfig
                    

Example 3: Deleting a Virtual Machine Scale Set

Remove-AzVMSS -ResourceGroupName "MyResourceGroup" -VMSSName "MyScaleSet" -Force