I have a script that makes a folder structure. It runs fine when run from the file server, sometimes asking to bypass the execution policy then it runs.
However this script needs to be run by certain users from a mapped share. When running it from a client machine I get:
“script.ps1 cannot be loaded because running scripts is disabled on this system. See about_execution_Policies”
Is there an line i can type at the start of the script to bypass this and allow it to run?
You can reboot and it’ll stay in ByPass or RemoteSigned. For ultimate security, you’d want the last line of your script to lock down which scripts are able to run again, so remove bypass, etc.
Although the idea is sound, I don’t like using one script to start another script. Especially when it’s 1 line… However the “-ExecutionPolicy Bypass” switch was exactly what I was going to suggest. You can use this method from a task schedule or from the powershell prompt itself.
As others have said, there are two explicit ways to do this.
Deploy a policy that sets the execution policy to remote signing, you will have to sign your scripts.
or
Make a .bat file that when launched will open powershell and run the command. The caveat here is that it is very important you get your switches correctly. If these need to be specific to the user running the script do NOT use -noprofile. If you want it to run silently in the background your batch file would look something like this.
EDIT: if your file is located on another UNC path the file would look like this. -file “\server\folder\script_name.ps1”
These toggles will allow the user to execute the powershell script by double clicking a batch file. There will be no window, no copyright logo, and no user interactivity. The perks of this, is the user does not see the background noise. I have had to do this recently. It works without muddling with all users’ execution policies.
Really makes you wonder how secure your environment is if you can run a script with -bypass flags. Also keep in mind things that would need administrative write access. But, what I have said above should point you in the right direction. Just make a .bat file with the one line of opening powershell. It feels clunky (it is) but it works.