Tim Kruger
Tim Kruger

Reputation: 897

How do I change the directory of the PowerShell cmd through a script

How would I go about doing what I mentioned in the subject line. Here are screenshots of what I mean:

before

script body

I was expecting the directory below to have changed to "C:\Program Files" after running the "Test.ps1" script?

after

Updated script after adding Write-Host $pwd

Write-Host $pwd added to script

Upvotes: 0

Views: 27482

Answers (2)

David Jones
David Jones

Reputation: 3342

There is no global 'current' directory, it is a property of the particular process you are working in. The 'current' directory for winword.exe may be very different to the 'current' directory of powershell.exe. And indeed, two different powershell processes can have different ideas of the 'current' directory.

So it would be foolish to expect that changing the 'current' directory in one powershell process would affect any other processes.

Upvotes: 1

Random206
Random206

Reputation: 816

Set-Location -Path "C:\Folder\SubFolder"

The above will change the directory to the given location as long as you have access to navigate to the location provided.

Upvotes: 3

Related Questions