Skip to content

Audit fixes (2026-11-18) #1

Audit fixes (2026-11-18)

Audit fixes (2026-11-18) #1

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
analyze:
name: PSScriptAnalyzer
runs-on: windows-latest
timeout-minutes: 15
steps:
# Every action is pinned to a full commit SHA. The comment names the tag it was taken from.
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force
# Per file, because a whole-tree run printed an internal NullReference in the audit.
# Tests\ is skipped: Pester mock bodies cannot see $script: variables, so the tests use one $global: table on purpose.
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
Import-Module PSScriptAnalyzer -RequiredVersion 1.25.0
$files = Get-ChildItem -Recurse -File -Include *.ps1, *.psm1, *.psd1 |
Where-Object { $_.FullName -notlike '*\Tests\*' -and $_.FullName -notlike '*\.git\*' }
$results = foreach ($file in $files) {
Invoke-ScriptAnalyzer -Path $file.FullName -Settings ./PSScriptAnalyzerSettings.psd1
}
Write-Host "Analyzed $($files.Count) file(s)."
if ($results) {
$results | Format-Table -AutoSize ScriptName, Line, RuleName, Severity, Message | Out-String -Width 250 | Write-Host
throw "PSScriptAnalyzer reported $(@($results).Count) finding(s)."
}
test:
name: Pester (${{ matrix.shell }})
runs-on: windows-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# pwsh is PowerShell 7. powershell is Windows PowerShell 5.1, which is what Intune runs.
shell: [pwsh, powershell]
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Pester
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# -SkipPublisherCheck: Windows PowerShell 5.1 ships Pester 3.4 signed by Microsoft
Install-Module -Name Pester -RequiredVersion 5.9.1 -Scope CurrentUser -Force -SkipPublisherCheck
- name: Parse every script
run: |
$errors = foreach ($file in Get-ChildItem -Recurse -File -Include *.ps1, *.psm1, *.psd1 | Where-Object { $_.FullName -notlike '*\.git\*' }) {
$tokens = $null; $parseErrors = $null
[System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$tokens, [ref]$parseErrors) | Out-Null
foreach ($e in $parseErrors) { "$($file.Name):$($e.Extent.StartLineNumber) $($e.Message)" }
}
if ($errors) { $errors | ForEach-Object { Write-Host $_ }; throw "Parse errors found." }
- name: Run Pester
run: |
Import-Module Pester -RequiredVersion 5.9.1
$config = New-PesterConfiguration
$config.Run.Path = './Tests'
$config.Run.Exit = $true
$config.Output.Verbosity = 'Normal'
Invoke-Pester -Configuration $config