PowerShell Genie

Find changed PowerShell files in Git

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

git diff with --name-only prints paths instead of patch content, and the pathspec arguments after the double dash restrict output to ps1 and psm1 files.

The script

Show reference output
1 git diff --name-only -- "*.ps1" "*.psm1"

Script reader

Inspect before you run

Inspection only

This is the page's actual command example. The browser does not execute it or contact a device, repository or API.

Inspection only — no command has run.

    Show reference output
    1 scripts/Backup-Files.ps1
    2 modules/Reporting/Reporting.psm1
    3 tests/Backup-Files.Tests.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.

    git diff --name-only -- "*.ps1" "*.psm1"
    1. Stage 1gitPositional values or no named parameters

      How it works

      git diff with --name-only prints paths instead of patch content, and the pathspec arguments after the double dash restrict output to ps1 and psm1 files. What comes back is a plain list of relative paths that PowerShell can consume as strings.

      Adapting it

      Compare against a branch rather than the working tree by supplying a revision range such as origin/main...HEAD, which is what a pull request check actually needs to examine.

      Requirements

      Git available on the path and the session running inside a repository.

      If the result is unexpected

      The changed-files list misses edits or includes unrelated files.

      Working-tree, staged and committed differences are separate Git comparisons.

      1. Identify the comparison boundary and inspect untracked files separately from tracked diffs.

      Validate the result

      The list matches the chosen working-tree or commit comparison.

      Keep the check reliable

      State the base revision and whether untracked files are included before running checks on the list.

      Primary documentation

      Files, storage and hashes documentation

      Continue
      Genie guideFind changed PowerShell files in Git

      git diff with --name-only prints paths instead of patch content, and the pathspec arguments after the double dash restrict output to ps1 and psm1 files.