Execution Policy for Script

Is there any way to run power-shell script without passing the ‘-Bypass’ flag or changing the execution policy on a machine? Is the only other way to get it working is to get it signed?

It depends on your environment. You can set the execution policy either by a policy or you can set it once by calling Set-ExecutionPolicy as administrator.

Is there a particular problem you try to solve?

I want to run the script in production, so I cannot change the execution policy of the machine

That does not explain nothing at all.

What does that mean … in production? :thinking: Why can’t you not change the execution policy? :thinking:

Are we talking about servers or clients? :thinking: About how many machines are we talking here? :thinking: Are we talking about domain joined machines or a workgroup? :thinking: How do you like to run the script? :thinking:

Here you have already 6 questions and I could think about more actually. :smirk:

… please keep in mind … we cannot see your screen or your environment and we cannot read your mind.

This seems backwards. Typically, you’d change the execution policy to an appropriate level to achieve the desired result (run a script.) You could make a permanent change or per invocation.

What is wrong with setting per invocation as Doug suggests?

I don’t really know who is gonna use this script, but I do know they won’t be changing the policies on their machine for running this.

I guess the option remaining is to get the script signed.

No the end user would not be changing the policy. The administrator of the machine that accepts/desires the script being ran would. Either that or the script would be ran with the execution policy set for just that invocation, like so.

Powershell.exe -ExecutionPolicy bypass -File path\to\script.ps1

You could call that with a batch file, a shortcut, or even a vbscript.

Getting the scripts signed may work depending if you sign it with a public cert or not. If you don’t then you’d need to configure the systems to trust the cert first. Which seems to be what your trying to avoid. Also keep in mind if the script is downloaded or copied it may need to be “unblocked” (through explorer or Unblock-File)

1 Like

You could start with answering some of the questions I asked. Then we might be able to help you better. :wink:

Finally got to know that I need not worry about execution policies, the guys running the script would be handling that.

Thank you guys for all the help!