Managing Azure Resources with PowerShell

Command-Line Control of Azure Infrastructure

Administrators can interact with Azure services through several interfaces: the web-based graphical portal, the cross-platform Azure CLI executable, and the Azure PowerShell module. To leverage PowerShell for infrastructure automation, the Az module must be integrated into your environment. This module introduces cmdlets targeting diverse services including compute, storage, networking, and identity management.

Environment Configuration

Starting with PowerShell 3.0, modules load automatically upon first cmdlet invocation. To prepare your workstation, fetch the module from the PowerShell Gallery. When prompted to trust the repository source, accept the installation.

# Acquire the Az module for the current user profile
Find-Module -Name Az -Repository PSGallery | Install-Module -Scope CurrentUser -Force

# Pull the latest version if previously deployed
Update-Module -Name Az

Utilize Get-Help at any time to explore cmdlet syntax and parameter definitions.

Once installed, authenticate against your cloud tenant. The connection command triggers an interactive login prompt to bind your session to an Azure subscription.

Connect-AzAccount

To confirm the active subscription context, inspect the current session state. You can list all available tenant subscriptions or explicitly shift context to a different one.

# Verify the present context
Get-AzContext

# Enumerate accessible subscriptions
Get-AzSubscription

# Pivot to a specific subscription ID
Set-AzContext -SubscriptionId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

Organizing Cloud Assets

Resources are logically grouped into containers. You can query existing groups or instantiate new ones by specifying a geographic region.

# Retrieve all groups in the active context
Get-AzResourceGroup

# Provision a new organizational unit
$rgParams = @{
    Name     = 'ProdAppResources'
    Location = 'EastUS'
}
New-AzResourceGroup @rgParams

Validate successful provisioning by querying all deployed assets within the scope.

Get-AzResource -ResourceGroupName $rgParams.Name

Compute Instance Lifecycle

The New-AzVM cmdlet provisions a virtual machine. The verb prefix dictates the lifecycle action: New for creation, Remove for deletion, Start/Stop/Restart for power states, and Update for configuration pushes.

$vmConfig = @{
    ResourceGroupName = 'ProdAppResources'
    Name              = 'WebNode01'
    Location          = 'EastUS'
    Image             = 'UbuntuLTS'
    Credential        = (Get-Credential)
}
New-AzVM @vmConfig

Retrieving a compute instance returns an object that can be manipulated in memory. Altering properties on this object and passing it back to the update cmdlet applies the modifications to the live infrastructure.

# Fetch the instance into a variable
$computeInstance = Get-AzVM -ResourceGroupName 'ProdAppResources' -Name 'WebNode01'

# Adjust the hardware sizing profile
$computeInstance.HardwareProfile.VmSize = 'Standard_DS3_v2'

# Persist the resized configuration to the cloud
Update-AzVM -ResourceGroupName 'ProdAppResources' -VM $computeInstance

Infrastructure Decommissioning

When a project concludes, entire resource containers can be eradicated in a single operation, removing all nested assets.

Remove-AzResourceGroup -Name 'ProdAppResources' -Force

Tags: PowerShell Azure Az Module Cloud Infrastructure Virtual Machines

Posted on Mon, 10 Aug 2026 16:58:51 +0000 by tc61380