Skip to content

Create main.yml

Create main.yml #1

Workflow file for this run

name: PowerShell Script Validator
# 1. TRIGGER:
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# 2. JOBS:
jobs:
lint-scripts:
name: Analyze PowerShell Code
# Spin up a fresh Windows virtual machine
runs-on: windows-latest
# 3. STEPS: tasks to execute
steps:
# Step A: Download repo code
- name: Checkout Repository
uses: actions/checkout@v4
# Step B: Run Posh
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
Write-Host "Installing PSScriptAnalyzer..."
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
Write-Host "Scanning repository for PowerShell scripts..."
$results = Invoke-ScriptAnalyzer -Path . -Recurse
if ($results) {
$results | Format-Table -AutoSize
Write-Error "Syntax issues or best-practice violations found!"
exit 1 # This tells GitHub to mark the pipeline as FAILED
} else {
Write-Host "Success! All scripts look good."
}