Skip to content

Add PSGet to PSResourceGet migration tool#2015

Open
adityapatwardhan wants to merge 8 commits into
masterfrom
adityapatwardhan-psget-migration-tool
Open

Add PSGet to PSResourceGet migration tool#2015
adityapatwardhan wants to merge 8 commits into
masterfrom
adityapatwardhan-psget-migration-tool

Conversation

@adityapatwardhan

Copy link
Copy Markdown
Member

PR Summary

Adds a self-contained PowerShell script (tool/migration/ConvertTo-PSResourceGet.ps1) that scans .ps1, .psm1, and .psd1 files for PowerShellGet v2 cmdlet usage and converts them to their PSResourceGet equivalents.

The tool uses PowerShell's AST parser to accurately identify PSGet v2 command invocations (avoiding false positives in comments or strings), then applies cmdlet name mappings, parameter renames, version range syntax transformations, and flags removed parameters with warnings.

Key capabilities:

  • 25 cmdlet mappings (e.g., Install-Module -> Install-PSResource, Find-DscResource -> Find-PSResource -Type DscResource)
  • Parameter transforms: version ranges (-MinimumVersion '1.0' -> -Version '[1.0,)'), renames (-AllowPrerelease -> -Prerelease, -NuGetApiKey -> -ApiKey), and smart -Force -> -Reinstall for Install commands
  • Two input modes: file/directory scanning (-Path) and direct string conversion (-InputScript)
  • Dry-run by default with a colored diff-style report; -Apply for in-place edits with .bak backups
  • 36 Pester tests covering all conversion scenarios

PR Context

Users migrating from PowerShellGet v2 to PSResourceGet need to update cmdlet names and parameters across potentially many scripts. This tool automates that process, reducing manual effort and the risk of missed or incorrect conversions. It is placed under tool/migration/ as a standalone utility.

PR Checklist

adityapatwardhan and others added 3 commits July 22, 2026 11:00
Adds a PowerShell-based migration tool that scans .ps1/.psm1/.psd1 files
for PowerShellGet v2 cmdlet usage and converts them to PSResourceGet
equivalents using AST-based parsing.

Features:
- 25 cmdlet mappings (Find-Module → Find-PSResource, etc.)
- Parameter transformations (version ranges, renames, removals)
- Dry-run report mode and in-place apply with backups
- 30 Pester tests covering all conversion scenarios

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds ConvertTo-PSResourceGetString function and -InputScript parameter
to the entry-point script, enabling direct string-to-string conversion
without needing files on disk.

Usage:
  .\ConvertTo-PSResourceGet.ps1 -InputScript 'Install-Module -Name Pester'
  'Find-Module -Name Az' | .\ConvertTo-PSResourceGet.ps1

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merge PSGetMigration.psm1/psd1 module into ConvertTo-PSResourceGet.ps1
as a self-contained script. All functions are defined inline and the
main entry point is guarded so dot-sourcing for tests works correctly.

Removes: PSGetMigration.psm1, PSGetMigration.psd1

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 22, 2026 20:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new migration utility under tool/migration/ to convert PowerShellGet v2 cmdlet usage to PSResourceGet equivalents, including a Pester test suite and user documentation to support scripted migrations across .ps1/.psm1/.psd1 files.

Changes:

  • Adds ConvertTo-PSResourceGet.ps1, an AST-based scanner/converter with cmdlet + parameter mapping and optional in-place edits with backups.
  • Adds Pester coverage for command/parameter conversions, warnings, and apply/backup behavior.
  • Adds a README documenting intended usage and conversion rules.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tool/migration/ConvertTo-PSResourceGet.ps1 Implements AST scanning + conversion logic, reporting, and apply-in-place behavior.
tool/migration/Tests/PSGetMigration.Tests.ps1 Adds Pester tests validating conversion scenarios and apply/backup flows.
tool/migration/README.md Documents mappings, parameter transforms, and intended usage patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tool/migration/ConvertTo-PSResourceGet.ps1
Comment thread tool/migration/ConvertTo-PSResourceGet.ps1
Comment thread tool/migration/README.md Outdated
Comment thread tool/migration/ConvertTo-PSResourceGet.ps1
@adityapatwardhan
adityapatwardhan marked this pull request as draft July 22, 2026 22:21
adityapatwardhan and others added 4 commits July 22, 2026 15:29
When -MinimumVersion or -MaximumVersion contains a variable reference
(e.g. \), use double quotes for the version range string
so the variable expands at runtime. Literal version strings continue to
use single quotes.

Before: -Version '(,\]'  (broken - no expansion)
After:  -Version "(,\]"  (correct - variable expands)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Replace Join-String (PS 7+ only) with -join operator for PS 5.1 compat
- Add known switch parameter list to prevent consuming positional args
  after switches like -Force (e.g. 'Install-Module -Force Pester')
- Fix README to document dot-sourcing instead of removed module manifest

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copy ConvertTo-PSResourceGet.ps1 to the 'migration' subdirectory of
the module output during build. The existing signing step already
signs all **\*.ps1 files under the output path, so the migration
tool will be signed as part of the release pipeline automatically.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds a 'TestMigrationTool' job in the Test stage that runs the
migration tool Pester tests on both PowerShell Core (pwsh) and
Windows PowerShell. The job is independent of the module build
since the migration tool is a standalone script.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Join-Path only accepts two path arguments in PS 5.1. Chain two
Join-Path calls instead of passing three positional arguments.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@adityapatwardhan
adityapatwardhan marked this pull request as ready for review July 23, 2026 17:50
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@adityapatwardhan

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants