r/PowerShell • u/Ancient-Blacksmith19 • Jan 27 '26
Question How to Set-Execution policy automatically?
Is there a way to have "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process" run at the start of my script in Powershell ISE without having to type it out every time?
16
Upvotes
25
u/marcdk217 Jan 27 '26
You can't put it within the script, that would defeat the purpose of having a script execution policy.
You can run the script using Powershell.exe -ExecutionPolicy RemoteSigned -File .\script.ps1 though. That will apply that executionpolicy to that script only which is similar to -scope process in a script context. Personally when using this, i just use Bypass instead of RemoteSigned.
6
u/zed0K Jan 27 '26
Set the scope to current user and it will stay forever.
5
u/DonL314 Jan 27 '26
Sorry but wouldn't it be easier signing your scripts instead?
2
u/shawski_jr Jan 27 '26
If you add it to your PowerShell profile it will run every time PowerShell opens
3
u/teethingrooster Jan 27 '26
You can modify the registry to set it for your profile here: HKCU\SOFTWARE\Policies\Microsoft\Windows\PowerShell
1
u/BlackV Jan 27 '26
depends where its being set to restricted (or what ever value)
but right now you are setting it to the process scope
-Scope Processso its only ever going to be temp1
u/mikenizo808 Jan 27 '26
Lots of great advice here already from others already. I just want to mention the default
Windows PowerShellcmdlet known asUnblock-File. This may pair nicely with your intentions to control the running of trusted or untrusted scripts.If you are familiar with what a blocked file looks like from right-click properties in Windows Explorer, using
Unblock-Filecan basically click the button for you.For domain joined targets you will likely not notice any blocking happening internally. However, if you have a bastion host (i.e. local Workgroup/not domain joined), then scripts created there and copied to the domain machine will likely be blocked.
With that said, be sure to vet the security of what you are unblocking first, by reading it and perhaps drag and drop it to virustotal or similar (i.e. their free web page).
If you know the source is trusted (i.e. internally generated, etc.) then you can simply add a line to unblock the file before running it. So essentially,
Unblock-Filemight resolve the issue for your use case instead of worrying aboutSet-ExecutionPolicy(though they do pair together nicely when needed).1
u/alconaft43 Jan 27 '26
GPO?
0
u/[deleted] Jan 27 '26
[deleted] — view deleted comment