Author Posts

February 20, 2017 at 4:06 pm

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>

February 20, 2017 at 4:16 pm

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

February 20, 2017 at 4:26 pm

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!

February 20, 2017 at 8:03 pm

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

February 21, 2017 at 11:24 am

Daniel Krebs,

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