0

I have a PowerShell script which contains a single command:

pwd

When I execute it from a (Windows 10) command line window, I get the following:

d:\Hudson_Test\workspace\CadGraphics>echo %cd%
d:\Hudson_Test\workspace\CadGraphics

d:\Hudson_Test\workspace\CadGraphics>powershell -file ShowLocation.ps1

Path
----
D:\hudson_test\workspace

As you can see, the current directory moves up one directory (from d:\hudson_test\workspace\CadGraphics to D:\hudson_test\workspace) when inside the PowerShell script.

I tested this on another (Win10) machine, and on that machine, the two paths were the same.

What is going on here, and how can I keep it from happening?

3
  • 7
    Do you have a profile? notepad $profile to check. Sounds like you have a profile that is setting the location. You can launch powershell without executing your profile with powershell -NoProfile -File ShowLocation.ps1 Commented Jan 6, 2017 at 0:33
  • I cannot reproduce the problem even on Windows 10. Commented Jan 6, 2017 at 1:28
  • Yes, it was the profile that was causing the problem. Launching powershell with the -NoProfile flag fixed my problem. Commented Jan 6, 2017 at 14:13

1 Answer 1

1

It should not unless the Profile is loading it everytime. Please try with

powershell -NoProfile -File FileName.ps1

Secondly , I would like you to store that in a variable and see the result from write-host

Sign up to request clarification or add additional context in comments.

2 Comments

Yup. It was loading a profile, which was setting its directory.
@PortMan: Great: happy to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.