0
votes

I'm working on power shell script using windows 2012 server, that do simple two functions

  • open powershell as an administrator
  • change the directory to c:\user\scrpt.bat

the code is:

powershell -Command "& {powershell Start-Process PowerShell -Verb RunAs; Set-Location C:\}

the problem is not when execute the first part, it's in the other part which is:

Set-Location C:\}

My question is there any way after running powershell as administrator execute the next command ?

I already tried to use semicolon ";" but no luck

1
if you're running a .bat file, why not just put all of that in the .bat file?mjolinor

1 Answers

1
votes

If you want to change directory for the process you're spawning - use -WorkingDirectory option:

powershell -Command "& { Start-Process PowerShell -Verb RunAs -WorkingDirectory 'D:' }"