Copy-Item From PSSession

Hello,

What would be the best way to copy files from remote powershell session? I thought Copy-Item cmdlet with parameter -FromSession would be the best choice. But then to make it work in the session configuration file I need to set LanguageMode to FullLanguage, add a few more cmdlets to VisibleCmdlets and my biggest concern is adding FileSystem to VisibleProviders. How can I ensure that Copy-Item cmdlet can access that folder only? Or maybe I’m going the wrong path?

I think what you want is shown in Examples 9, 10 and 11 in the Copy-Item documentation. If you need more specific help, please show your code (at least the relevant portion of it).

Turns out I just needed to include “MountUserDrive = $true” in session configuration and copy files from user psdrive.

New-PSSessionConfigurationFile -Path .\Test.pssc -SessionType RestrictedRemoteServer -MountUserDrive -VisibleCmdlets Copy-Item -Full

Now everything works the way I want it to.

Now I’m stuck with another problem. For some reason -Filter parameter does not work when copying from pssession, for example

[pre]Copy-Item -Path “C:\Source” -Destination “C:\Destination” -Recurse -Filter “username.json” -Force[/pre]

copies only “username.json” files, but if I try to copy from pssession

[pre]Copy-Item -Path “User:\Source” -Destination “C:\Destination” -Recurse -FromSession $session -Filter “username.json” -Force[/pre]

then copies everything. Or am I doing something wrong here?