Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9258

Run Multiple Commands As Admin From PS1 File ( Windows Terminal)

$
0
0

This PS1 File (test.ps1), while executed, will run The Commands Pushd $Home; bcdedit /enum bootmgr; pause As Admin in PWSH.exe its self.

# test.ps1$AL = "-NoProfile -WindowStyle Maximized -ExecutionPolicy Bypass", "-Command", "Pushd $Home; bcdedit /enum bootmgr; pause"Start -Verb RunAs -FilePath pwsh.exe -ArgumentList $AL

What is the writing format, if I execute it (test.ps1), then will opened in Windows Terminal Elevated/ As Admin?

I tried:

# test.ps1$AL = "-M -p 'PowerShell'", "pwsh.exe -ExecutionPolicy Bypass -Command `"Pushd $Home; bcdedit /enum bootmgr; pause`""Start -Verb RunAs -FilePath wt.exe -ArgumentList $AL

giving the errors:

[error 2147942402 (0x80070002) when launching `" pause"']

[error 2147942402 (0x80070002) when launching `" bcdedit /enum bootmgr"']

I have also tried other formats but the error still persists.

Only works if one command:

# test.ps1$AL = "-M -p 'PowerShell'", "pwsh.exe -ExecutionPolicy Bypass -Command `"bcdedit /enum bootmgr`""Start -Verb RunAs -FilePath wt.exe -ArgumentList $AL

Viewing all articles
Browse latest Browse all 9258

Trending Articles