Skip to main content

PowerShell Scripting Guide

Reference Azure PowerShell

DOCUMENT CATEGORY: Reference SCOPE: PowerShell automation patterns and helper usage PURPOSE: Document how Azure Local PowerShell automation is structured and executed MASTER REFERENCE: Microsoft Learn - PowerShell

Status: Active

Overview​

PowerShell provides the orchestration layer for much of the Azure Local automation estate. It is used to load variables, execute helper-driven workflows, run platform-specific deployment tasks, and bridge stages where Infrastructure as Code tools cannot fully automate the outcome.

Where PowerShell Fits​

AreaTypical Use
Variable loadingRead and validate infrastructure.yml
Script orchestrationChain multi-step deployment tasks
Azure automationExecute Az module workflows and helper functions
On-premises executionConfigure nodes, trigger validations, and perform operational tasks
Wrapper scriptsDrive Terraform, Ansible, and external tooling consistently

Common Script Patterns​

PatternPurpose
Direct ScriptRun directly on the target node or management host
Orchestrated ScriptExecute from a management server across multiple systems
Azure CLI VariantPowerShell wrapper around az commands where needed

Variable Loading​

PowerShell automation starts by loading the shared configuration, the master infrastructure.yml:

Import-Module ./scripts/common/infrastructure/AzlInfrastructure.psm1
$infra = Import-AzlInfrastructure -Path ./infrastructure.yml # stops if the file has errors

The script resolves environment-specific values from the central source of truth instead of hard-coding them inline. A test fails the build when a script carries a value that a deployment chooses. A script parameter that is not registered in the master registry fails a test too.

Helper Usage​

Common helpers cover:

  • Loading and validating the infrastructure file (AzlInfrastructure.psm1)
  • Variable lookups by path (Get-AzlInfrastructureValue)
  • Resolving secret references: keyvault://, env://, file:// and command:// (AzlSecret.psm1)
  • Writing the Terraform and Ansible variable files (config/variables/scripts/New-IacVariableFiles.ps1)
  • Progress lines with an optional -LogPath file, and preflight validation

Execution Guidance​

Use PowerShell when you need:

  • Strong operational control over sequence and retries
  • Local execution on Windows-based management systems
  • Deep integration with Azure PowerShell modules
  • A wrapper layer around Terraform, Ansible, or Azure CLI tasks

For the execution model used by the main delivery runbook, also see How to Use This Runbook.

Entry Points for the Azure Local Deployment Flow​

These scripts take the master infrastructure.yml and run unchanged on a workstation or in a pipeline (PowerShell 7):

ScriptPhaseGuide
scripts/common/discovery/Invoke-AzlDiscoveryRun.ps1Discovery, read only: the BMC hardware inventory (any maker), the Dell iDRAC discovery, the Azure tenant and the Active Directory inventory, into one report (discovery-report.json, summary.md). Exit code 0 every step succeeded, 1 a step failed, 2 bad input, including a file that cannot be read as YAML (nothing runs)Task 02: Hardware Discovery
scripts/deploy/04-cluster-deployment/phase-03-os-configuration/Invoke-AzureLocalOsConfiguration.ps1OS configuration of every node: plan, apply, verify, one reportAutomated OS configuration
scripts/deploy/04-cluster-deployment/phase-05-cluster-deployment/Invoke-AzureLocalPreClusterVerification.ps1The pre-cluster verification gate, read only: every prerequisite check before the ARM Validate, with a verdict the ARM run readsPre-cluster verification gate
scripts/deploy/04-cluster-deployment/phase-05-cluster-deployment/Invoke-AzureLocalArmDeployment.ps1Preconditions, ARM Validate, approval, ARM DeployARM Validate and Deploy

Each has a pipeline on GitHub Actions, GitLab CI and Azure DevOps that runs the script and nothing else: see the route table.

Repository Areas​

PathPurpose
scripts/common/Shared helpers and reusable utilities
scripts/deploy/Deployment phase scripts. The generated script status page says which task has a real script
scripts/deploy/07-validation-handover/Validation checks, the deployment documentation and the customer transfer
config/variables/Shared configuration consumed by the scripts

Example Exports​

./config/variables/scripts/New-IacVariableFiles.ps1 -InfrastructureFile ./infrastructure.yml -OutputDirectory D:\work\iac

PreviousUpNext
Ansible PlaybooksPart 3: Automation GuidesARM Validate and Deploy