ByPass MachinePolicy and UserPolicy when executing unsigned powershell script file

Hi All,

On my machine i have AllSigned policy set for MachinePolicy and UserPolicy 

I am able to execute scripts in powershell ISE Windows except powershell script files.

Is it possible to override these 2 policies and execute unsigned powershell script file ?


 >Get-ExecutionPolicy -list

                                                                               Scope                                                                      ExecutionPolicy
                                                                               -----                                                                      ---------------
                                                                       MachinePolicy                                                                            AllSigned
                                                                          UserPolicy                                                                            AllSigned
                                                                             Process                                                                            Undefined
                                                                         CurrentUser                                                                            Undefined
                                                                        LocalMachine                                                                               Bypass



TIA

September 6th, 2015 10:00am

You can run PowerShell.exe with a script as an argument and also bypass the execution policy using the command line documentation below:

https://technet.microsoft.com/en-us/%5Clibrary/Hh847736.aspx

You could use something similar to "PowerShell.exe -file <pathtofile> -executionpolicy bypass

Free Windows Admin Tool Kit Click here and download it now
September 6th, 2015 1:59pm

Thanks Rich,

I was using the EXACTLY same approach. It did not work.  I am researching if it's possible to bypass using alternative approach.

Thank again

September 6th, 2015 10:58pm

Can you post the command that you used? What was the error message you received?

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 3:29am

Please see error below. Based on my research, looks like there is no way to bypass user/machine policy if they are set to AllSigned.

E:\Test> powershell.exe .\LoadFiles.ps1 -ExecutionPolicy ByPass

.\LoadFiles.ps1 : File E:\Test\LoadFiles.ps1 cannot be loaded. The file 
E:\Test\LoadFiles.ps1 is not digitally signed. The script will not execute on the system. For more information, see 
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\LoadFiles.ps1
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess



Get-ExecutionPolicy -list



    Scope                                                                      ExecutionPolicy
                                                                                -----                                                                      ---------------
                                                                        MachinePolicy                                                                            Undefined
                                                                           UserPolicy                                                                            AllSigned
                                                                              Process                                                                            Undefined
                                                                          CurrentUser                                                                            Undefined
                                                                         LocalMachine                                                                            Undefined






LoadFiles.ps1
=============================
Write-Host "Hello World"

September 7th, 2015 11:19am

How about changing the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

Set/create 'ExecutionPolicy' (REG_SZ) to 'RemoteSigned'

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 12:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics