- Courses
- đ»Programming Languages
- đȘPowerShell
- Enterprise-Grade PowerShell
- Building Tooling and Automation Frameworks
- Integrating PowerShell with CI/CD Pipelines
On this page
Integrating PowerShell with CI/CD Pipelines: Automation Guide
Updated on June 28, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
Integrating PowerShell into CI/CD pipelines transforms automation from isolated scripts into a fully orchestrated delivery system. PowerShell becomes a firstâclass citizen in build and deployment workflows, enabling you to validate infrastructure, enforce compliance, generate artifacts, deploy cloud resources, and run postâdeployment verification â all in a controlled, repeatable manner. Modern CI/CD platforms such as GitHub Actions and Azure DevOps support PowerShell natively across Windows, Linux, and macOS runners. The PowerShell project itself has migrated its entire CI/CD infrastructure to GitHub Actions, demonstrating the viability of PowerShellâdriven pipelines at scale. Key practices include structuring scripts for nonâinteractive execution, retrieving secrets securely from vaults, running Pester tests on every commit, packaging and publishing modules to internal repositories or PowerShell Gallery, and deploying infrastructure through PowerShell cmdlets. With the release of DSC v3 â a complete rebuild written in Rust and built for CI/CDâdriven environments â PowerShell's role in configuration management and infrastructure as code has been fundamentally modernised.
PowerShell as a Pipeline Execution Engineâ
CI/CD systems such as GitHub Actions, Azure DevOps, GitLab CI, and Jenkins all support PowerShell as a native execution environment. This allows you to run PowerShell scripts at every stage of the pipeline:
- Build: compile modules, validate syntax, run Pester tests
- Package: bundle modules, generate manifests, prepare artifacts
- Deploy: provision cloud resources, configure systems, run orchestrations
- Verify: test deployments, validate state, collect logs
PowerShell becomes the automation layer that binds these stages together. The PowerShell project's migration from Azure DevOps to GitHub Actions illustrates this evolution â legacy Azure Pipelines files have been rendered obsolete as the project fully embraces GitHub Actions for CI/CD.
Preparing Automation for Pipeline Executionâ
Before integrating with CI/CD, your PowerShell automation must be structured to run nonâinteractively. This requires:
- No prompts
- No interactive credential requests
- Deterministic behaviour
- Clear exit codes
- Structured output
A pipeline must be able to run your automation unattended and interpret its results reliably.
Example: Ensuring NonâInteractive Executionâ
param(
[Parameter(Mandatory)]
[string]$ConfigPath,
[switch]$VerboseOutput
)
$ErrorActionPreference = "Stop"
The $ErrorActionPreference = "Stop" setting ensures that failures stop the pipeline immediately. All required input is provided through parameters, eliminating any interactive prompts.
Running PowerShell in CI/CD Environmentsâ
GitHub Actionsâ
GitHub Actions supports PowerShell on Windows, Linux, and macOS runners using the pwsh shell:
steps:
- name: Run PowerShell script
shell: pwsh
run: ./Deploy.ps1 -ConfigPath config.json
The pwsh shell invokes PowerShell Core, ensuring crossâplatform compatibility. For complex builds, the PowerShell project uses composite actions and log grouping to make build logs navigable.
Azure DevOpsâ
Azure DevOps provides a dedicated PowerShell task:
- task: PowerShell@2
inputs:
filePath: "Deploy.ps1"
arguments: "-ConfigPath config.json"
pwsh: true
The PowerShell v2 (PowerShell@2) task runs PowerShell scripts that can access the Azure DevOps REST API, work with Azure DevOps work items, manage tests, or call other services. You can use predefined variables or userâdefined variables in PowerShell scripts, and you can also set multiâjob output variables to make variables available to other jobs.
GitLab CIâ
GitLab CI supports PowerShell through its script section:
deploy:
script:
- pwsh ./Deploy.ps1 -ConfigPath config.json
Jenkinsâ
Jenkins can execute PowerShell scripts using the powershell step:
powershell """
./Deploy.ps1 -ConfigPath config.json
"""
The script remains identical across platforms because PowerShell is crossâplatform.
Integrating Secret and Credential Retrievalâ
CI/CD pipelines must never store secrets in scripts. Instead, they retrieve secrets from:
- Pipeline secret stores (GitHub Secrets, Azure DevOps Variable Groups)
- Azure Key Vault
- AWS Secrets Manager
- HashiCorp Vault
- PowerShell SecretManagement
Example: Retrieving a Secret in a Pipelineâ
$apiKey = Get-Secret -Name "ProdApiKey"
Invoke-Deployment -ApiKey $apiKey
PowerShell SecretManagement provides a standardised, vaultâagnostic interface for securing secrets, making it a perfect match for CI/CD scenarios. It allows a pipeline to access credentials or tokens securely while keeping plain text out of the code.
Validating Automation with Pesterâ
Pester tests run automatically in CI/CD pipelines to ensure that:
- Modules import correctly
- Functions behave as expected
- Configurations are valid
- Infrastructure definitions are correct
Example: Running Pester in a Pipelineâ
Invoke-Pester -Output Detailed -CI
The -CI flag produces structured output that CI/CD systems can interpret. Pester offers unit and integration testing to validate modules and scripts, preventing regressions in future changes.
GitHub Actions Exampleâ
name: Run Tests using Windows PowerShell
run: ./powershell/tests/pester.ps1
- uses: actions/upload-[email protected]
This workflow runs Pester tests and uploads test results as artifacts.
Packaging and Publishing Modulesâ
CI/CD pipelines can package and publish PowerShell modules to internal repositories or the PowerShell Gallery, ensuring consistent distribution across teams.
Example: Packaging a Moduleâ
Publish-Module -Path .\Company.Automation -Repository InternalPSRepo
This allows teams to install the module directly from the repository:
Install-Module Company.Automation
The PowerShell Gallery has specific recommendations for what constitutes a good package, including manifest parameters, code improvement through reviews and PSScriptAnalyzer, versioning, documentation, and testing.
Controlled Publishingâ
Many production pipelines use manual triggering to prevent accidental publications to PowerShell Gallery. The final task publishes the module using the native Publish-Module cmdlet. Publishing to PowerShell Gallery lowers user friction (Install-Module) but must be protected because publishing is hard to undo and requires API key handling.
Deploying Infrastructure Through PowerShellâ
PowerShell integrates directly with cloud providers, making it ideal for infrastructure deployment.
Azure Exampleâ
New-AzResourceGroupDeployment `
-ResourceGroupName ProdRG `
-TemplateFile main.bicep `
-TemplateParameterFile prod.json
AWS Exampleâ
New-CFNStack `
-StackName ProdStack `
-TemplateBody (Get-Content template.yaml -Raw)
These commands run inside the pipeline, ensuring consistent, versioned deployments.
PowerShell Desired State Configuration (DSC) in CI/CDâ
PowerShell DSC plays a critical role in CI/CD pipelines by ensuring that server configurations are consistent and repeatable. DSC v3 represents a complete rebuild of the platform â written in Rust and built for today's CI/CDâdriven world.
Key Changes in DSC v3â
- Runs as a standalone command rather than relying on the Local Configuration Manager
- Accepts resources written in any language
- Native integration with CI/CD pipelines and reporting tools
- Orchestrates state across Windows, Linux, and macOS
- Provides a CLI (
dsc) with subcommands to list, test, and apply resources and configurations - Requires PowerShell 7.2 or later
DSC v3 is an evolution in cloudânative configuration management for crossâplatform environments. It enables teams to combine configurations and resources while reducing complexity when multiple preferred configurations exist for achieving a server deployment end state.
PostâDeployment Validationâ
After deployment, PowerShell verifies that the environment is in the expected state.
Example: Verifying a VM is Runningâ
$status = Get-AzVM -Name Web01 -ResourceGroup ProdRG -Status
if ($status.Statuses[1].Code -ne "PowerState/running") {
throw "VM Web01 is not running."
}
This allows the pipeline to fail early if the deployment is incomplete or misconfigured.
Summaryâ
Integrating PowerShell with CI/CD pipelines elevates automation from manual execution to a fully orchestrated, versioned, and validated delivery process. PowerShell becomes the engine that drives build, test, deployment, and verification stages across any platform. By structuring scripts for nonâinteractive execution, retrieving secrets securely, running Pester tests, packaging modules, deploying infrastructure, and validating results, you create a robust automation framework that operates reliably at enterprise scale. With the advent of DSC v3, PowerShell's role in configuration management and infrastructure as code has been fundamentally modernised for today's CI/CDâdriven world.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Creating Internal Toolkits
Next
đPython
-
PowerShell as a Pipeline Execution Engine
-
Preparing Automation for Pipeline Execution
- Example: Ensuring NonâInteractive Execution
-
Running PowerShell in CI/CD Environments
- GitHub Actions
- Azure DevOps
- GitLab CI
- Jenkins
-
Integrating Secret and Credential Retrieval
- Example: Retrieving a Secret in a Pipeline
-
Validating Automation with Pester
- Example: Running Pester in a Pipeline
- GitHub Actions Example
-
Packaging and Publishing Modules
- Example: Packaging a Module
- Controlled Publishing
-
Deploying Infrastructure Through PowerShell
- Azure Example
- AWS Example
-
PowerShell Desired State Configuration (DSC) in CI/CD
- Key Changes in DSC v3
-
PostâDeployment Validation
- Example: Verifying a VM is Running
-
Summary
