How to avoid the "Execution Policy Change" message?

Home Forums Scripting PowerShell How to avoid the "Execution Policy Change" message?

This topic contains 5 replies, has 5 voices, and was last updated by  Kasi77 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • dreivilo47
    dreivilo47
    Participant
    #167600

    When I run a ps1-script from my flash drive, I get sometimes the “Execution Policy Change” message.
    Which line(s) do I need to add to the top of my script to avoid this?


    wullieb1
    Moderator
    #245781

    You actually need to sign your script.

    However you can run the script using this

    PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1[/CODE][CODE]PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1[/CODE]


    Anonymous
    #372104

    Don’t know if you can do that from inside a script you’re trying to execute without any other actions, because that would be an obvious security flaw since any script could execute itself without hesitation. Any script I run, I set to execute from a scheduled task. In the ‘Activity’ tab of the Task, you include ‘-ExecutionPolicy Bypass’ in the same field that you call the script. The script runs under whatever the creds are, from the task which calls it. Once that task completes, the system default execution policy is reinforced once more.
    As long as the Task is set to allow a manual run, you can run it at any time. Unless you can set your Powershell security via Group Policy.


    Kasi77
    Member
    #391882
    wullieb1;n517453 wrote:
    You actually need to sign your script.

    However you can run the script using this

    PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1[/CODE][/QUOTE]

    Thank you for your answer and possible solution [USER=”3705″]wullieb1[/USER].[CODE]PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1[/CODE]

    Thank you for your answer and possible solution [USER=”3705″]wullieb1[/USER].


    Kasi77
    Member
    #391883
    RicklesP;n517464 wrote:
    Don’t know if you can do that from inside a script you’re trying to execute without any other actions, because that would be an obvious security flaw since any script could execute itself without hesitation. Any script I run, I set to execute from a scheduled task. In the ‘Activity’ tab of the Task, you include ‘-ExecutionPolicy Bypass’ in the same field that you call the script. The script runs under whatever the creds are, from the task which calls it. Once that task completes, the system default execution policy is reinforced once more.
    As long as the Task is set to allow a manual run, you can run it at any time. Unless you can set your Powershell security via Group Policy.

    Thank you for your answer [USER=”68253″]RicklesP[/USER].


    James Haynes
    Member
    #252124

    when i run them as .ps1, i get errors like that, but if i run the .ps1 from a batch, i dont, so long as it have it like this:

    powershell -command “& {Set-ExecutionPolicy Remotesigned}”
    powershell -file C:UserswhoeverDesktopmyPSscript.ps1

    …before i call the .ps1 in the batch that i run as admin. if i want to run them as a .ps1, i have to run PS as admin and do like “Set-ExecutionPolicy -ExecutionPolicy RemoteSigned” prior.

    but im a novice at scripting. i just had that problem in the past, so i call it from a batch with the above lines and it always works without a problem no matter where i run it from (key or share or cloud) so i have continued to do it like that.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.