PSHELL changes directory

May 20, 2008
12,393
140
Syracuse, NY, USA
When there is no persistent PowerShell interpreter PSHELL changes the current working directory to %SYSTEMROOT\System32. It does not do this if a persistent PowerShell interpreter is running,

Code:
v:\> pshell /c

v:\> pshell /s "echo foo"
foo

c:\windows\system32> v:

v:\> pshell /s "echo foo"
foo

v:\>
 
There's an alias for that;
Code:
e:\utils>which pshell
pshell is an alias : *pshell %@pshell[set-location '%_cwd']

Joe
That doesn't seem to work if there's no persistent PowerShell interpreter running. And if there is a PowerShell interpreter running, there is no problem.

Code:
v:\> which pshell
pshell is an alias : *pshell %@pshell[set-location '%_cwd']

v:\> pshell /c

v:\> pshell /s "echo foo"
foo

c:\windows\system32>

This one works.

Code:
alias pshell `set ocwd=%_cwds & *pshell %$ & %ocwd & unset /q ocwd`
 
Here's another.

Code:
v:\> which pshell
pshell is an alias : setlocal & *pshell %$ & endlocal

v:\> pshell /c

v:\> pshell /s "echo foo"
foo

v:\> [code]

But I don't think an alias should be needed ... eh?
 

Similar threads