I'm working on my dotfiles and I'm wanting to create a batch script that will do some initial setup for me when switching to a new computer, like using psget to install modules, etc... I'd also like it to go ahead and change my ExecutionPolicy to something usable.
I created a batch file that simply fires off a powershell script under the Bypass
ExecutionPolicy:
powershell -ExecutionPolicy ByPass
-NoLogo -NoProfile -NoExit
-File .\set-policy.ps1
set-policy.ps1
attempts to run powershell as administrator to change the ExecutionPolicy:
Start-Process powershell -verb runas
-ArgumentList "-No Exit -Command { Set-ExecutionPolicy Restricted }"
Unfortunately, that doesn't seem to do that trick (output below). Not sure what the problem is.
Set-ExecutionPolicy Restricted
PS C:\windows\system32> Get-ExecutionPolicy
RemoteSigned
Any tips on how to use a batch file + powershell script to change execution policy?
-verb runas
which will bring up the uac prompt and launch powershell as administrator.