Specify path on remote session

Welcome Forums General PowerShell Q&A Specify path on remote session

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
1 year, 12 months ago.

  • Author
    Posts
  • #64798

    Participant
    Points: 44
    Rank: Member

    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

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

    • #64806

      Participant
      Points: 44
      Rank: Member

      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

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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

      Participant
      Points: 44
      Rank: Member

      Daniel Krebs,

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

The topic ‘Specify path on remote session’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort