ExecutionPolicy parameter

This topic contains 10 replies, has 3 voices, and was last updated by  Simeon Iksanov 2 years ago.

  • Author
    Posts
  • #32065

    Simeon Iksanov
    Participant

    powershell.exe -? says there is a parameter ExecutionPolicy

    when I try to run

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

    RemoteSigned

    why?

  • #32066

    Noam lesnik
    Participant

    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

    Simeon Iksanov
    Participant

    but i still cannot run remote scripts..

  • #32068

    Noam lesnik
    Participant

    You specify the script path with -File parameter?

  • #32069

    Simeon Iksanov
    Participant

    yes

  • #32070

    Noam lesnik
    Participant

    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

    Simeon Iksanov
    Participant

    you are trying to run _local_ script

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

  • #32073

    Noam lesnik
    Participant

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

  • #32077

    Noam lesnik
    Participant

    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

    Dave Wyatt
    Moderator

    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

    Simeon Iksanov
    Participant

    Noam, Dave thanks a lot

    now it is clear to me

You must be logged in to reply to this topic.