+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, Change Powershell ExecutionPolicy to RemoteSigned via BATCH in Coding and Web Development; So I'm pinning together a batch file that automatically installes Windows Management Framework 3.0 and the domain Powershell certificates for ...
  1. #1

    Garacesh's Avatar
    Join Date
    Jan 2012
    Posts
    3,414
    Thank Post
    1,304
    Thanked 502 Times in 368 Posts
    Rep Power
    240

    Change Powershell ExecutionPolicy to RemoteSigned via BATCH

    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
    Code:
    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:
    Code:
    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?

  2. #2


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,775
    Thank Post
    262
    Thanked 2,963 Times in 2,178 Posts
    Rep Power
    838
    Either of the commands below will set the execution policy (as long as they are run elevated).

    Code:
    powershell.exe -Command "Set-ExecutionPolicy RemoteSigned -Force"
    Code:
    REG ADD "HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v ExecutionPolicy /d RemoteSigned /t REG_SZ /f

  3. #3

    Garacesh's Avatar
    Join Date
    Jan 2012
    Posts
    3,414
    Thank Post
    1,304
    Thanked 502 Times in 368 Posts
    Rep Power
    240
    Quote Originally Posted by Arthur View Post
    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.



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 0
    Last Post: 24th January 2008, 03:58 PM
  2. Sending files to Capita via FTP (or not).
    By Heebeejeebee in forum MIS Systems
    Replies: 18
    Last Post: 22nd November 2007, 12:30 PM
  3. change taskbar back to blue group policy
    By cooper in forum Windows
    Replies: 5
    Last Post: 15th August 2007, 11:40 AM
  4. emac to promethean via serial to usb adapter
    By k1r5tymm in forum Hardware
    Replies: 0
    Last Post: 8th February 2007, 11:30 PM
  5. Replies: 7
    Last Post: 17th February 2006, 04:49 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •