When you download a script off the internet and try to run it, if you have not previously configured PowerShell, it will throw a nasty error in red font. This is enough to scare most users off, but there is an easy fix.
PowerShell has a number of execution modes that define what type of code it is permitted to run, this is governed by a registry key that lives in the HKLM hive. There are 4 different execution modes, they are:
- Restricted: Default execution policy, does not run scripts, interactive commands only.
- All Signed: Runs scripts; all scripts and configuration files must be signed by a publisher that you trust; opens you to the risk of running signed (but malicious) scripts, after confirming that you trust the publisher.
- Remote Signed: Local scripts run without signature. Any downloaded scripts need a digital signature, even a UNC path.
- Unrestricted:Runs scripts; all scripts and configuration files downloaded from communication applications such as Microsoft Outlook, Internet Explorer, Outlook Express and Windows Messenger run after confirming that you understand the file originated from the Internet; no digital signature is required; opens you to the risk of running unsigned, malicious scripts downloaded from these applications
To change it to unrestricted run the following command from an administrative PowerShell:
Set-ExecutionPolicy UnrestrictedYou will be asked if you are sure that you want to change the Execution Policy hit the enter button again.
You can now run your downloaded scripts without a problem. However, it’s a serious security risk if you forget to set the Execution Policy back to Restricted mode. You could probably guess how to set it back to Restricted, but incase you don’t:
Set-ExecutionPolicy RestrictedAgain you will be asked if you are sure that you want to change the execution mode, go ahead and hit enter.
No comments:
Post a Comment