On this page

PowerShell Cloud Automation: Azure, AWS & Best Practices

Updated on June 27, 2026

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

PowerShell provides a unified automation engine for managing cloud resources across Azure and AWS. The Az PowerShell module is Microsoft's recommended tool for Azure management, offering thousands of cross‑platform cmdlets organized by service. For AWS, the AWS.Tools modules provide an idiomatic PowerShell experience built on the AWS SDK. In both clouds, the most secure authentication methods are managed identities (Azure) and IAM roles (AWS), which eliminate the need to store credentials. Enterprise‑grade automation requires idempotent workflows that combine declarative infrastructure templates (Bicep for Azure, CloudFormation for AWS) with PowerShell orchestration, ensuring predictable, repeatable, and auditable deployments.


Azure Automation with the Az PowerShell Module​

Azure PowerShell is the collection of official Microsoft PowerShell modules for managing Azure resources. The current version, the Az PowerShell module, replaces the deprecated AzureRM module and is the recommended way to interact with Azure from PowerShell.

Installing the Az Module​

The Az module is a wrapper that includes separate submodules for each Azure service:


Install-Module -Name Az -Scope CurrentUser -Force

Installing the Az module pulls in all service‑specific modules such as Az.Compute, Az.Network, and Az.Storage. For smaller installations, you can install only the modules you need:


Install-Module -Name Az.Accounts

Install-Module -Name Az.Compute

PowerShell 7.2 or higher is the recommended version for use with the Az module on all platforms, including Windows, Linux, and macOS. The module is also compatible with Windows PowerShell 5.1.

Authentication Methods​

Azure PowerShell supports multiple authentication methods depending on your use case. For ad‑hoc management, interactive login is appropriate. For automation, service principals or managed identities are required.

Interactive login – used for development and ad‑hoc management:


Connect-AzAccount

This opens a browser window for authentication. Starting in September 2025, Azure PowerShell requires multifactor authentication (MFA) when signing in with a Microsoft Entra ID user identity.

Service principal – used for CI/CD pipelines and automation scripts:


Connect-AzAccount -ServicePrincipal `

    -Tenant $tenantId `

    -ApplicationId $appId `

    -CertificateThumbprint $thumbprint

Service principals support RBAC, auditing, and least‑privilege access. As of Az PowerShell module version 7.x, New-AzADServicePrincipal no longer assigns the Contributor role by default.

Managed identity – the preferred method for Azure resources:


Connect-AzAccount -Identity

This authenticates using the managed identity of the current Azure resource (VM, Function App, Automation Account, or container). No credentials are stored, transmitted, or exposed.

Managing Azure Resources​

Azure resources follow a consistent pattern: resource group → resource → configuration.

Create a resource group


New-AzResourceGroup -Name "ProductionRG" -Location "japaneast"

This command creates a resource group in the specified Azure region. Resource groups serve as logical containers for related resources.

Create a virtual machine


New-AzVM `

    -ResourceGroupName "ProductionRG" `

    -Name "WebServer01" `

    -Location "japaneast" `

    -Image "Win2022Datacenter"

The New-AzVM cmdlet handles the complexity of VM creation, including network interfaces, disks, and other dependencies.

Create a storage account


New-AzStorageAccount `

    -ResourceGroupName "ProductionRG" `

    -Name "prodstoragejpe01" `

    -Location "japaneast" `

    -SkuName Standard_LRS

The New-AzStorageAccount cmdlet creates a storage account with the specified SKU. The name must be globally unique across Azure.

Idempotent Automation with Bicep and PowerShell​

While PowerShell can create resources imperatively, enterprise automation typically combines declarative templates with PowerShell orchestration. Azure Bicep is a domain‑specific language for deploying Azure resources declaratively. Bicep files are idempotent: deploying the same file multiple times results in the same resource state.

Deploying a Bicep template from PowerShell


New-AzResourceGroupDeployment `

    -ResourceGroupName "ProductionRG" `

    -TemplateFile ".\main.bicep" `

    -Parameter @{ environment = "prod" }

This command deploys the Bicep template to the specified resource group, applying the provided parameters. PowerShell orchestrates the deployment while Bicep defines the infrastructure.

The recommended enterprise pattern combines:


AWS Automation with AWS Tools for PowerShell​

AWS provides a full PowerShell experience through the AWS Tools for PowerShell, which are built on the AWS SDK for .NET.

Installing AWS Tools​

AWS offers two installation options:

Modular approach (recommended) – install only the modules you need:


Install-Module -Name AWS.Tools.Installer

Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3,AWS.Tools.IdentityManagement

The modular version reduces download time, import time, and memory usage.

Monolithic approach – install all services in one package:


Install-Module -Name AWSPowerShell

The monolithic module is the older approach and is not recommended for production environments.

AWS Tools for PowerShell are compatible with Windows PowerShell 5.1 and PowerShell Core 6+ on Windows, Linux, and macOS.

Authentication Methods​

AWS Tools for PowerShell support flexible credential handling:

Credential profiles – for local development:


Set-AWSCredential -ProfileName "default"

Profiles are stored in ~/.aws/credentials and can include access keys, region, and output format.

Access keys – for automation scripts:


Set-AWSCredential -AccessKey $key -SecretKey $secret -StoreAs "ProdAutomation"

Access keys grant programmatic access to AWS resources and must be managed securely.

IAM roles – the best practice for AWS compute resources:

When running on EC2, Lambda, ECS, or other AWS compute services, IAM roles provide temporary credentials automatically. No secrets are stored or transmitted.

IAM Identity Center – for centralized access management:

AWS Tools for PowerShell support IAM Identity Center, allowing you to start an access portal session and authenticate without long‑term credentials.

Managing AWS Resources​

AWS cmdlets map directly to AWS API operations.

Create an S3 bucket


New-S3Bucket -BucketName "prod-bucket-jp-01"

Bucket names must be globally unique across all AWS accounts.

Upload a file to S3


Write-S3Object -BucketName "prod-bucket-jp-01" -File "report.csv"

Launch an EC2 instance


New-EC2Instance `

    -ImageId "ami-1234567890abcdef0" `

    -InstanceType "t3.micro" `

    -MinCount 1 -MaxCount 1

The New-EC2Instance cmdlet launches EC2 instances with the specified AMI and instance type. The MinCount and MaxCount parameters control the number of instances launched.


Designing Cloud Automation Workflows​

Expert‑level automation requires more than calling individual cmdlets. Enterprise workflows must be:

Enterprise Automation Pattern​

A typical enterprise workflow follows this structure:

  1. Authenticate using managed identity, IAM role, or service principal
  2. Validate environment and resource state before making changes
  3. Deploy infrastructure declaratively (Bicep for Azure, CloudFormation for AWS)
  4. Configure using PowerShell for post‑deployment tasks
  5. Store outputs and metadata in a central system
  6. Log and audit all operations

PowerShell in CI/CD Pipelines​

PowerShell integrates seamlessly with CI/CD pipelines:


# GitHub Actions example

- name: Deploy to Azure

  uses: azure/login@v2

  with:

    creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Run PowerShell deployment

  run: |

    ./deploy.ps1 -Environment "prod"

PowerShell is a cornerstone of modern IT management, automating everything from infrastructure provisioning to application configuration.


Cross‑Cloud Automation Patterns​

Many enterprises operate in hybrid or multi‑cloud environments. PowerShell is uniquely positioned to automate across providers because it is cross‑platform, supports both Azure and AWS natively, integrates with CI/CD pipelines, and can orchestrate external tools.

A common cross‑cloud pattern includes:

This creates a unified automation layer regardless of cloud provider.


Summary​

Automating cloud resources with PowerShell requires mastering both Azure and AWS modules, along with a deep understanding of authentication, resource models, and enterprise governance. Key principles include:

PowerShell is the de‑facto automation language for Windows infrastructure and Azure cloud operations. With these skills, it becomes a powerful, cloud‑agnostic automation engine capable of managing infrastructure at enterprise scale.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Infrastructure Automation

Next

Virtual Machines