PowerShell Genie

Review unsigned PowerShell scripts in a repository

Script 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Check PowerShell script signatures without executing the files. Identify unsigned scripts and review their signature status.

The script

1PS> Get-ChildItem -Path . -Filter *.ps1 -File -Recurse | ForEach-Object {
2PS> $sig = Get-AuthenticodeSignature -LiteralPath $_.FullName
3PS> [pscustomobject]@{ Path= $_.FullName; Status= $sig.Status; Signer=if($sig.SignerCertificate){ $sig.SignerCertificate.Subject}else{ $null } } } | Where-Object Status -ne 'Valid' | Sort-Object Status,Path

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 SignerCertificate Status StatusMessage Path
    2 ----------------- ------ ------------- ----
    3 CN=Microsoft Corporation, O=Microsoft... Valid Signature verified script.ps1
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-ChildItem -Path . -Filter *.ps1 -File -Recurse | ForEach-Object { $sig = Get-AuthenticodeSignature -LiteralPath $_.FullName [pscustomobject]@{ Path= $_.FullName; Status= $sig.Status; Signer=if($sig.SignerCertificate){ $sig.SignerCertificate.Subject}else{ $null } } } | Where-Object Status -ne 'Valid' | Sort-Object Status,Path
    1. Stage 1Get-ChildItem-Path -Filter -File -Recurse
    2. Stage 2ForEach-ObjectPositional values or no named parameters
    3. Stage 3Where-Object-ne
    4. Stage 4Sort-ObjectPositional values or no named parameters

      How it works

      Check PowerShell script signatures without executing the files. Identify unsigned scripts and review their signature status. The report keeps the signature status and signer together so unsigned, hash-mismatched and trust-chain failures are not flattened into one bucket.

      Adapting it

      Include .psm1 and .psd1 when module files are in scope. Export the objects to CSV for a remediation queue rather than formatting them first.

      Primary documentation

      Get-ChildItem reference · Where-Object reference · ForEach-Object reference

      Continue
      Genie guideReview unsigned PowerShell scripts in a repository

      Check PowerShell script signatures without executing the files. Identify unsigned scripts and review their signature status.