PowerShell Scripting Guide
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
| Area | Typical Use |
|---|---|
| Variable loading | Read and validate infrastructure.yml |
| Script orchestration | Chain multi-step deployment tasks |
| Azure automation | Execute Az module workflows and helper functions |
| On-premises execution | Configure nodes, trigger validations, and perform operational tasks |
| Wrapper scripts | Drive Terraform, Ansible, and external tooling consistently |
Common Script Patterns
| Pattern | Purpose |
|---|---|
| Direct Script | Run directly on the target node or management host |
| Orchestrated Script | Execute from a management server across multiple systems |
| Azure CLI Variant | PowerShell 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://andcommand://(AzlSecret.psm1) - Writing the Terraform and Ansible variable files (
config/variables/scripts/New-IacVariableFiles.ps1) - Progress lines with an optional
-LogPathfile, 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):
| Script | Phase | Guide |
|---|---|---|
scripts/common/discovery/Invoke-AzlDiscoveryRun.ps1 | Discovery, 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.ps1 | OS configuration of every node: plan, apply, verify, one report | Automated OS configuration |
scripts/deploy/04-cluster-deployment/phase-05-cluster-deployment/Invoke-AzureLocalPreClusterVerification.ps1 | The pre-cluster verification gate, read only: every prerequisite check before the ARM Validate, with a verdict the ARM run reads | Pre-cluster verification gate |
scripts/deploy/04-cluster-deployment/phase-05-cluster-deployment/Invoke-AzureLocalArmDeployment.ps1 | Preconditions, ARM Validate, approval, ARM Deploy | ARM 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
| Path | Purpose |
|---|---|
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
Relationship to Other Guides
- Use Terraform Modules when PowerShell is orchestrating Terraform workflows
- Use Ansible Playbooks when PowerShell is driving or preparing Ansible execution
- Use the Implementation Guide for the broader deployment sequence
Navigation
| Previous | Up | Next |
|---|---|---|
| Ansible Playbooks | Part 3: Automation Guides | ARM Validate and Deploy |