In a PowerShell script, I have to call a batch file in an elevated window. So I do
Start-Process my.bat -Verb runas
Now, my.bat
What you want isn't possible. For security reasons elevated processes don't inherit the parent's environment. What you can do is create a wrapper script that you run elevated and have that script set the environment variables from parameters before running my.bat
.
IIRC "runas" isn't enabled for PowerShell scripts by default, so the wrapper script would have to be a batch file:
@echo off
set "VARIABLE1=%1"
set "VARIABLE2=%2"
call "C:\path\to\my.bat"
Run it like this:
Start-Process .\wrapper.ps1 -ArgumentList 'foo', 'bar' -Verb runas