I recently noticed that PowerShell does not set up quite the same "execution
environment" for external executables as would normally be expected (that is,
as one is accustomed to from CMD.EXE). Specifically, the external executable
"sees" the current directory (as set by "Set-Location", or its alias "cd")
for the current drive only. For all other drives, the external executable
"sees" the root, rather than the actual current directory that has been set
in PowerShell.
For example, suppose that "cd c:\abc" and "cd d:\xyz" have been issued and
the current drive is the "C:" drive. If you issue the external command:
comp c: d:
.... you would expect it will compare the "c:\abc" folder with the "d:\xyz"
folder ... and in a CMD.EXE shell, that is what happens. But under
PowerShell, it compares the "c:\abc" folder with "d:\". If you then make the
"D:" drive your current drive, in PowerShell, and issue the same command, it
will compare "c:\" with "d:\xyz".
The same thing happens in batch files run under PowerShell, because the
child instance of CMD.EXE that runs that batch file "sees" the current
PowerShell directory on the current drive only.
One can easily compensate for this peculiarity. Just remember, when running
external executables, to always specify the fully-qualified path for any
drives other than the current drive. For example, when the current drive is
the "C:" drive:
comp c: d:\xyz
But such a workaround is unnecessary when running PowerShell cmdlets, and
PowerShell scripts that do not call external executables.
Bill
Palo Alto, California


