Announcement

Collapse
No announcement yet.

How to avoid the "Execution Policy Change" message?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to avoid the "Execution Policy Change" message?

    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?

  • #2
    You actually need to sign your script.

    However you can run the script using this

    Code:
    PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1

    Comment


    • #3
      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.
      *RicklesP*
      MSCA (2003/XP), Security+, CCNA

      ** Remember: credit where credit is due, and reputation points as appropriate **

      Comment


      • #4
        Originally posted by wullieb1 View Post
        You actually need to sign your script.

        However you can run the script using this

        Code:
        PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1
        Thank you for your answer and possible solution wullieb1.

        Comment


        • #5
          Originally posted by RicklesP View Post
          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 RicklesP.

          Comment


          • #6
            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:\Users\whoever\Desktop\myPSscript.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.
            its easier to beg forgiveness than ask permission.
            Give karma where karma is due...

            Comment

            Working...
            X