Skip to content

refactor: Improve Get-PowerShellPortable reliability and cross-platform support#190

Merged
SamErde merged 5 commits into
mainfrom
updates
May 9, 2026
Merged

refactor: Improve Get-PowerShellPortable reliability and cross-platform support#190
SamErde merged 5 commits into
mainfrom
updates

Conversation

@SamErde

@SamErde SamErde commented May 9, 2026

Copy link
Copy Markdown
Owner

Summary

Refactors \Get-PowerShellPortable\ with several quality improvements:

Changes

  • Parameter validation: Added [ValidateScript({ Test-Path -Path \ -PathType Container })]\ to the -Path\ parameter to ensure a valid directory is provided before attempting a download
  • Platform detection refactor: Cached [System.Runtime.InteropServices.RuntimeInformation]\ in a \\ variable to eliminate repetitive type references
  • Cross-platform fix: \Unblock-File\ now only runs on Windows (it fails on Linux/macOS)
  • Stream disposal: Combined duplicate Linux/macOS GZip extraction blocks into a single \ ry/finally\ block that properly disposes \GZipStream, \TargetStream, and \SourceStream\
  • Output stream: Changed \Write-Output\ to \Write-Information\ for status messages (correct stream usage)
  • Error handling: Changed \ hrow\ to \Write-Error\ for the unknown OS case (less disruptive, allows caller to handle)
  • Regex simplification: Simplified directory-name extraction regex to use \GetFileNameWithoutExtension\ + a single \.tar$\ replace
  • Documentation: Improved parameter descriptions and comment-based help

…ons in Get-PowerShellPortable.

Refactor platform checks and OS-specific commands with more efficient handling.
Combine redundant Linux and macOS extraction code blocks and dispose of streams properly.
Copilot AI review requested due to automatic review settings May 9, 2026 17:16
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codacy-production

codacy-production Bot commented May 9, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors Get-PowerShellPortable to improve reliability and cross-platform behavior when downloading/extracting the latest PowerShell portable archive.

Changes:

  • Adds -Path directory validation and improves help text/parameter descriptions.
  • Refactors platform detection and adjusts OS-specific behavior (e.g., Windows-only Unblock-File).
  • Consolidates Linux/macOS gzip extraction into a single try/finally disposal flow and moves status messages to the Information stream.

Comment thread src/PSPreworkout/Public/Get-PowerShellPortable.ps1 Outdated
SamErde and others added 2 commits May 9, 2026 13:20
…ecks

The module declares PowerShellVersion = '5.1', so the ?. operator
(PS 7+ only) must not be used. Initialize streams to \ before
the try block and use explicit if-checks in the finally block.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/PSPreworkout/Public/Get-PowerShellPortable.ps1 Outdated
Specify Read/FileShare.Read for the source stream and Write/FileShare.None
for the target stream to follow least-privilege and avoid potential
UnauthorizedAccessException on restricted filesystems.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SamErde SamErde merged commit 3200f63 into main May 9, 2026
11 checks passed
@SamErde SamErde deleted the updates branch May 9, 2026 17:38
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