Elevate rights in current directory with PowerShell

Viewed 121

For example I'm in C:\Users\User\Desktop\Tools and I'm trying to stay here as admin.

I tried this way, gluing together different commands:

"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -noexit" & -windowstyle hidden -Command Start-Process powershell  -ArgumentList '-NoExit', '-Command cd %V' -Verb runAs""

The PATH changes to C:\WINDOWS\system32 why? How to elevate rights in current directory via simple command?

1 Answers

Use $PWD from the calling process to change the location on startup:

Start-Process powershell -ArgumentList '-NoExit', "-Command cd '$pwd'; & .\actual\script\you\want\to\run.ps1" -Verb runAs
Related