Only Three ways to do this:
- Do it manually on the machine of choice.
- Use Group Policy to enable it on all machines or selected machines
- Use .bat file to execute the script from it.
Option 1:
Set-ExecutionPolicy $POLICY -Force
Restricted
- No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned
- Only scripts signed by a trusted publisher can be run.
RemoteSigned
- Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted
- No restrictions; all Windows PowerShell scripts can be run.
Option 2:
- Navigate under Computer Configuration to Policies\Administrative Templates\Windows Components\Windows PowerShell. You should see a setting called Turn on Script Execution
- Double-click the setting. You will want to enable it and select an option from the drop down.
- Pick the policy of your choice. AllSigned, RemoteSigned and Unrestricted
- GPO is safe, but it can also turn unsafe really fast. Make sure you test your new GPO out, before putting it into production.
Option 3:
Run the folling inside a .bat file
powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file "name_of_script.ps1"
Hope this helps you find the answer you are looking for.