Copy-Item From PSSession

Welcome Forums General PowerShell Q&A Copy-Item From PSSession

Viewing 3 reply threads
  • Author
    Posts
    • #193805
      MK
      Participant
      Topics: 5
      Replies: 8
      Points: 22
      Rank: Member

      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?

    • #193901
      Senior Moderator
      Topics: 5
      Replies: 133
      Points: 706
      Helping Hand
      Rank: Major Contributor

      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).

    • #193952
      MK
      Participant
      Topics: 5
      Replies: 8
      Points: 22
      Rank: Member

      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.

    • #194111
      MK
      Participant
      Topics: 5
      Replies: 8
      Points: 22
      Rank: Member

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

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

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

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

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

Viewing 3 reply threads
  • The topic ‘Copy-Item From PSSession’ is closed to new replies.