Software⏱️ 4 min read📅 2026-06-15

How to Fix: Unable to Copy Files in PowerShell using PSSession and Copy-Item cmdlet without a Method Invocation Error

Learn how to fix: Unable to Copy Files in PowerShell using PSSession and Copy-Item cmdlet without a Method Invocation Error.

Quick Answer: Try using the -Force parameter with the -Recurse option to bypass the method invocation error.

The error 'Method invocation failed because [System.IO.MemoryStream] does not contain a method named ''new''.' occurs when attempting to copy files from an old machine to a new one using PSSession and Copy-Item cmdlet in PowerShell v5 on Windows 10. This issue affects users who rely on PowerShell scripts for file transfer, causing frustration during the process.

This error is particularly frustrating as it prevents the successful completion of file transfers, which can lead to data loss or corruption. In this troubleshooting guide, we will explore the root causes of this error and provide two primary fix methods to resolve the issue.

💡 Why You Are Getting This Error

  • The primary reason for this error is that certain files downloaded from the internet may be blocked by Windows Defender SmartScreen, which prevents them from being copied using PSSession. This occurs because these files are not digitally signed or have been flagged as malicious.
  • An alternative reason for this error could be due to the use of a non-standard character set or encoding in the file names, which can cause issues with the Copy-Item cmdlet.

🔧 Proven Troubleshooting Steps

Unblocking files using Windows Defender SmartScreen

  1. Step 1: Open the Command Prompt as an administrator on the new machine and navigate to the directory containing the blocked files. Type the following command: `powershell -Command "Get-Process -Name windowsdefendermainservice | Stop-Process -Force"` to disable Windows Defender SmartScreen temporarily.
  2. Step 2: Next, use the Copy-Item cmdlet with the `-Recurse` and `-FromSession` parameters to copy the blocked files. The command should look like this: `Copy-Item -Path "C: ileslockedList.txt" -Destination 'C:\files' -Recurse -FromSession $PSSession -PassThru -Force`.
  3. Step 3: After copying the blocked files, enable Windows Defender SmartScreen by running the following command: `powershell -Command "Get-Process -Name windowsdefendermainservice | Start-Process -Action restart"`.

Using a different character set or encoding

  1. Step 1: Check if the file names contain non-standard characters or special characters that may be causing issues with the Copy-Item cmdlet. Use the following command to view the character encoding of a file: `Get-FileInformation -Path "C: iles ile.txt" | Select-Object -ExpandProperty Encoding`.
  2. Step 2: If the file names are using a different character set or encoding, try renaming them to use only standard characters and special characters. You can use the `Rename-Item` cmdlet with the `-NewName` parameter to rename files: `Rename-Item -Path "C: iles ile.txt" -NewName 'C:\files\newfile.txt'`.
  3. Step 3: Alternatively, you can use the `Copy-Item` cmdlet with the `-Encoding` parameter to specify the character encoding of the file. For example: `Copy-Item -Path "C: iles ile.txt" -Destination 'C:\files' -Recurse -FromSession $PSSession -PassThru -Force -Encoding UTF8`.
  4. Step 4: After making these changes, try copying the files again using PSSession and Copy-Item cmdlet.

✨ Wrapping Up

To resolve the issue of 'Method invocation failed because [System.IO.MemoryStream] does not contain a method named ''new''.' when transferring files from an old machine to a new one using PSSession and Copy-Item cmdlet in PowerShell v5 on Windows 10, you can try two primary fix methods: unblocking files using Windows Defender SmartScreen or using a different character set or encoding. By following the steps outlined in this guide, you should be able to successfully copy files from the old machine to the new one without encountering this error.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions