I've already read and tried various ways, but it just won't take it... I even tried to escape the spaces as well as trying to add extra quotes (escaped quotes) in front of the path...
$cmd = 'powershell.exe'
$dir = 'C:\Program Files (x86)\W T F'
$inner = "-NoExit -Command cd $dir"
$arguments = "Start-Process powershell -ArgumentList '$inner' -Verb RunAs"
& $cmd $arguments
It keeps giving me this:
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:22
+ cd C:\Program Files (x86)\W T F
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I tried with a different path, say C:\Blah\W T F
it would still complaint about the spaces that are inside W T F
.
Edit: Basically I needed to start an elevated powershell
and then CD into my directory to run some post install script. But I am having a hard time CD into my directory, I was able to start my elevated powershell, but it always goes to c:\windows\system32
.
Edit2:
$PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
Edit3:
I have this script call load-ems.ps1 (to load Exchange Management Shell), and I'm trying to launch that shell as elevated. But my problem is that:
- the shell would start in system32 and won't find my scripts
- if i try to CD to my directory, i can't.
. ".\find-exchange.ps1"
$remoteexchangeps1 = Find-Exchange
$commands = @(
". '$remoteexchangeps1';",
"Connect-ExchangeServer -auto -ClientApplication:ManagementShell;",
".\plugin-reinstall.ps1;"
)
$command = @($commands | % {$_})
powershell.exe -noexit -command "$command"
& "C:\Program Files (x86)\W T F"
?& : The term 'C:\Program Files (x86)\W T F' is not recognized as the name of a cmdlet,
$env:ProgramFiles(x86)
.