Windows: Execute powershell script - how it works
For security reasons, you cannot run the Powershell script under Windows by default. Instead, the small programs are blocked. In this practical tip we show you how you can still start and use the script.
Run Powershell script on Windows - you have to do that
If you want to run a Powershell script on Windows, you must first remove the block:
- Right click on the Powershell shortcut and select "Run as administrator". You may need to confirm this step.
- Execute the "Set-ExecutionPolicy RemoteSigned" command here so that the scripts are executed.
- Note: This command executes all scripts, which can result in a security risk.
- "RemoteSigned" requires a digital signature to execute it and uses this for the scripts downloaded from the Internet. Windows always runs local scripts that you have created on the PC.
- You can therefore use the "AllSigned" variable instead of "RemoteSigned". So all scripts are executed with a digital signature. If the signature is unknown, you will be asked for permission.
- The "Unrestricted" variable executes all scripts, but a warning is issued for unsigned scripts downloaded from the Internet. In this case the command is "Set-ExecutionPolicy Unrestricted".
- With the command "powershell -ep RemoteSigned -file MyScript.ps1" you can set up an exception for your file. Replace the "MyScript.ps1" variable with your actual file name.
Execute powershell script - edit group rights
Alternatively, you can also edit the group rights under Windows 10. The advantage: You don't have to choose between the confusing commands.
- Enter "Computer and user configuration" in the Windows search and start the program of the same name.
- Switch here to the "Guidelines" and then to "Administrative Templates".
- Under "Windows Components" look for the folder "Windows PowerShell".
- Double-click the "Allow script execution" entry.
- Here you will find the setting options "Allow local scripts and remotely signed scripts", "Allow only signed scripts" and "Allow all scripts".
- For security reasons, we recommend that you use the "Allow local scripts and remote signed scripts" option. This protects your PC optimally.
These instructions are based on Windows 8 or Windows 10. We will show you the most important commands of the Powershell in the next practical tip.