Garacesh Posted June 16, 2014 Posted June 16, 2014 So I'm pinning together a batch file that automatically installes Windows Management Framework 3.0 and the domain Powershell certificates for scripts signed by me, but by default ExecutionPolicy is set to Restricted and it needs to be RemoteSigned.. So far the best method I've got is echo Set-ExecutionPolicy RemoteSigned -Force|clip && start powershell.exe This launches a Powershell CLI and I just paste the command in, press Enter and done! But since there's ways to pass commands to Powershell via batch (using -command) I figured I'd try and automate this bit.. The closest I've gotten is: PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -NoExit -ExecutionPolicy Bypass -Command "{Set-ExecutionPolicy RemoteSigned -Force}"' -Verb RunAs}" This successfully launches an administrative Powershell window (after UAC prompt) and 'Set-ExecutionPolicy RemoteSigned -Force' does appear in the window. It then waits for further commands with 'PS C:\Windows\system32> _'.. Get-ExecutionPolicy tells me it's Bypass still (which I'd expect for that instance) but if I check with a different powershell window it's still set as Unrestricted (testing on my machine) I figure it's probably a security thing, but is there a way of passing it automatically?
Arthur Posted June 16, 2014 Posted June 16, 2014 Either of the commands below will set the execution policy (as long as they are run elevated). powershell.exe -Command "Set-ExecutionPolicy RemoteSigned -Force" REG ADD "HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v ExecutionPolicy /d RemoteSigned /t REG_SZ /f
Garacesh Posted June 16, 2014 Author Posted June 16, 2014 Either of the commands below will set the execution policy (as long as they are run elevated). The batch itself can't be run as an admin else the Framework Management installer fails (I have no idea why..) which is why it first launches a regular powershell window that then launches an administrative powershell window.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now