Add PSGet to PSResourceGet migration tool#2015
Draft
adityapatwardhan wants to merge 4 commits into
Draft
Conversation
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>
adityapatwardhan
requested review from
SydneyhSmith,
alerickson,
anamnavi and
shammu1
as code owners
July 22, 2026 20:25
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
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 on lines
+186
to
+188
| if ($parseErrors.Count -gt 0) { | ||
| Write-Warning "Parse errors in '$Path': $($parseErrors | ForEach-Object { $_.Message } | Join-String -Separator '; ')" | ||
| } |
Comment on lines
+266
to
+273
| if ($null -ne $element.Argument) { | ||
| $paramValue = $element.Argument.Extent.Text | ||
| } | ||
| elseif (($i + 1) -lt $elements.Count -and | ||
| $elements[$i + 1] -isnot [System.Management.Automation.Language.CommandParameterAst]) { | ||
| $i++ | ||
| $paramValue = $elements[$i].Extent.Text | ||
| } |
Comment on lines
+77
to
+81
| ## Using as a Module | ||
|
|
||
| ```powershell | ||
| Import-Module .\tool\migration\PSGetMigration.psd1 | ||
|
|
Comment on lines
+347
to
+359
| if ($null -ne $minimumVersion -and $null -ne $maximumVersion) { | ||
| $minVal = $minimumVersion.Trim("'`"") | ||
| $maxVal = $maximumVersion.Trim("'`"") | ||
| $newParams.Add("-Version '[$minVal,$maxVal]'") | ||
| } | ||
| elseif ($null -ne $minimumVersion) { | ||
| $minVal = $minimumVersion.Trim("'`"") | ||
| $newParams.Add("-Version '[$minVal,)'") | ||
| } | ||
| elseif ($null -ne $maximumVersion) { | ||
| $maxVal = $maximumVersion.Trim("'`"") | ||
| $newParams.Add("-Version '(,$maxVal]'") | ||
| } |
adityapatwardhan
marked this pull request as draft
July 22, 2026 22:21
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Adds a self-contained PowerShell script (
tool/migration/ConvertTo-PSResourceGet.ps1) that scans.ps1,.psm1, and.psd1files 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:
Install-Module->Install-PSResource,Find-DscResource->Find-PSResource -Type DscResource)-MinimumVersion '1.0'->-Version '[1.0,)'), renames (-AllowPrerelease->-Prerelease,-NuGetApiKey->-ApiKey), and smart-Force->-Reinstallfor Install commands-Path) and direct string conversion (-InputScript)-Applyfor in-place edits with.bakbackupsPR 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
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.