Specify path on remote session

This topic contains 4 replies, has 3 voices, and was last updated by  Vandrey Trindade 7 months, 4 weeks ago.

  • Author
    Posts
  • #64798

    Vandrey Trindade
    Participant

    Hi,

    How can I remotely connect to a specific path on a server using Enter-PSSession?
    I'm trying to change the path where it connects:

    [SERVER]: PS C:\Users\Administrator\Documents>
  • #64801

    Don Jones
    Keymaster

    You don't; you'd run a CD command after connecting. That path is essentially hardcoded into the endpoint behavior.

    • #64806

      Vandrey Trindade
      Participant

      I tried to add a "Set-Location" on the next line of the function but it takes more time to validate the credentials, so it just returns an error saying that that path doesn't exists.
      Anyways, thanks a lot!

  • #64837

    Daniel Krebs
    Moderator

    It should work if you initiate a session first, use Invoke-Command to change the path and enter the session afterwards.

    $session = New-PSSession -ComputerName Machine01
    Invoke-Command -Session $session -ScriptBlock { Set-Location D:\ }
    Enter-PSSession -Session $session
    
    • #64885

      Vandrey Trindade
      Participant

      Daniel Krebs,

      Worked like a charm! Thanks a lot!
      This forum is the best!

You must be logged in to reply to this topic.