Skip to content

Add PSGet to PSResourceGet migration tool#2015

Draft
adityapatwardhan wants to merge 4 commits into
masterfrom
adityapatwardhan-psget-migration-tool
Draft

Add PSGet to PSResourceGet migration tool#2015
adityapatwardhan wants to merge 4 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 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 thread tool/migration/README.md
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
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>
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