ExecutionPolicy parameter

Welcome Forums General PowerShell Q&A ExecutionPolicy parameter

This topic contains 10 replies, has 3 voices, and was last updated by

 
Participant
2 years, 11 months ago.

  • Author
    Posts
  • #32065

    Participant
    Points: 0
    Rank: Member

    powershell.exe -? says there is a parameter ExecutionPolicy

    when I try to run

    c:\ > powershell.exe -executionPolicy Unrestricted -command "Get-ExecutionPolicy"

    RemoteSigned

    why?

  • #32066

    Participant
    Points: 0
    Rank: Member

    Hi,

    you can run it like this to get the expected output:
    powershell.exe -executionPolicy Unrestricted -command "Get-ExecutionPolicy -Scope Process"

    I hope this helps.

  • #32067

    Participant
    Points: 0
    Rank: Member

    but i still cannot run remote scripts..

  • #32068

    Participant
    Points: 0
    Rank: Member

    You specify the script path with -File parameter?

  • #32069

    Participant
    Points: 0
    Rank: Member

    yes

  • #32070

    Participant
    Points: 0
    Rank: Member

    That is odd,

    I've just downloaded a script from Script Center to try it on my machine and it works as expected.
    My execution policy is RemoveSigned so i cannot run it in normal powershell window, but it works if i run it like this
    powershell.exe -executionPolicy Unrestricted -command "Get-ExecutionPolicy -Scope Process" -File "C:\Users\\Desktop\ActiveSyncReport.ps1"

    Edit:
    forget all i worte before. it doesnt work here too.

  • #32072

    Participant
    Points: 0
    Rank: Member

    you are trying to run _local_ script

    try
    powershell.exe -executionPolicy Unrestricted -File "\\some\network\share\script.ps1

  • #32073

    Participant
    Points: 0
    Rank: Member

    Just edited my last post, it's not working for me too

  • #32077

    Participant
    Points: 0
    Rank: Member

    After some more digging around, i think the this is an issue of executionpolicy scope precedence, its described here:

    https://technet.microsoft.com/en-us/library/hh847748.aspx

    i got a clue to this by running "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted" and getting an the following error:
    Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will
    retain its current effective execution policy of RemoteSigned. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".
    At line:1 char:1

  • #32078

    Member
    Points: 0
    Rank: Member

    Looks like you've got an execution policy being assigned by Group Policy, which is why your effective policy is still set to RemoteSigned. You can see more detail with: powershell.exe -ExecutionPolicy Bypass -Command Get-ExecutionPolicy -List

    If the MachinePolicy or UserPolicy options are anything other than "Undefined", then they will take precedence over everything else in the list (including Process, which is what gets set by powershell.exe's parameter.

  • #32106

    Participant
    Points: 0
    Rank: Member

    Noam, Dave thanks a lot

    now it is clear to me

The topic ‘ExecutionPolicy parameter’ is closed to new replies.