Skip to content

Fix the scripts used for Copy-Item -FromSessoin/-ToSession scenarios and also enable tests - #27773

Open
Dongbo Wang (daxian-dbw) wants to merge 3 commits into
PowerShell:masterfrom
daxian-dbw:copy-item
Open

Fix the scripts used for Copy-Item -FromSessoin/-ToSession scenarios and also enable tests #27773
Dongbo Wang (daxian-dbw) wants to merge 3 commits into
PowerShell:masterfrom
daxian-dbw:copy-item

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Aug 6, 2026

Copy link
Copy Markdown
Member

PR Summary

  • Fix the scripts used for Copy-Item -FromSessoin/-ToSession and PSEdit. They use -Encoding Byte, which only works in PS5.1. In PS 7+, we need to use -AsByteStream instead. So, those scenarios (copy alternate data stream to/from remote PS 7 session and edit file from a remote PS 7 session) have been broken for a long time.
  • The remote tests for Copy-Item have always been disabled. This PR re-enables those tests for Windows (the HelperRemoting module only works on Windows).

PR Checklist

@azure-pipelines

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

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-Test Indicates that a PR should be marked as a test change in the Change Log label Aug 6, 2026
@daxian-dbw Dongbo Wang (daxian-dbw) changed the title Enable and fix remote tests for Copy-Item Fix the scripts used for Copy-Item -FromSessoin/-ToSession scenarios and also enable tests Aug 6, 2026
@daxian-dbw
Dongbo Wang (daxian-dbw) marked this pull request as ready for review August 7, 2026 17:20
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a review from a team as a code owner August 7, 2026 17:20
Copilot AI lite review requested due to automatic review settings August 7, 2026 17:20
@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
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the PowerShell-side scripts used by Copy-Item -FromSession/-ToSession (including alternate data stream copy) and PSEdit so they read/write raw bytes correctly in PowerShell 7+ by using -AsByteStream (while retaining -Encoding Byte for Windows PowerShell / Desktop). It also attempts to re-enable previously-disabled remoting tests for Copy-Item on Windows via the HelpersRemoting module.

Changes:

  • Update remote copy helper scripts to use Get-Content/Add-Content -AsByteStream when running on PSEdition = Core.
  • Update the PSEdit support script to use Get-Content -AsByteStream on PSEdition = Core.
  • Rework Copy-Item remoting tests to use New-RemoteSession and add Windows/admin gating tags.

Reviewed changes

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

File Description
test/powershell/Modules/Microsoft.PowerShell.Management/Copy-Item.Tests.ps1 Re-enables/adjusts remoting tests using HelpersRemoting and adds platform/admin gating.
src/System.Management.Automation/namespaces/FileSystemProvider.cs Fixes alternate stream remote copy scripts to use -AsByteStream on PowerShell Core.
src/System.Management.Automation/engine/hostifaces/HostUtilities.cs Fixes PSEdit remote file-open script to use -AsByteStream on PowerShell Core.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Copy-Item.Tests.ps1 Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Test Indicates that a PR should be marked as a test change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants