On this page

Integrating PowerShell with CI/CD Pipelines: Automation Guide

Updated on June 28, 2026

Enrico Hochkoeppler Profile

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:

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:

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:

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:

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​

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!

Buy Me a Coffee

Previous

Creating Internal Toolkits

Next

🐍Python