Among the best methods to guard your group in opposition to malicious PowerShell scripts is to leverage the PowerShell execution insurance policies as a device for limiting the usage of scripts. Among the best methods to perform that is to configure the execution coverage at the Group Policy level. On this article, I\u2019ll present you the way it\u2019s performed.\nConfiguring Group Coverage\nMicrosoft makes it comparatively simple to regulate your PowerShell execution coverage enforcement on the Group Coverage degree. To take action, merely open the Group Coverage Editor and cargo your Group Coverage of selection. Subsequent, navigate by means of the console tree to Laptop ConfigurationPoliciesAdministrative TemplatesWindows ComponentsWindows PowerShell. While you do, you must see a Group Coverage setting referred to as Flip On Script Execution. You\u2019ll be able to see what this appears to be like like within the screenshot under. By the way, this setting can be utilized on the person degree.\n\nYow will discover the PowerShell-related Group Coverage settings at Laptop ConfigurationPoliciesAdministrative TemplatesWindows ComponentsWindows PowerShell.\n\nNow, double click on on the Flip On Script Execution coverage setting, and you can be allowed to configure it. You\u2019ll be able to see what choices exist for this coverage setting within the screenshot under.\n\nAs you take a look at the screenshot above, you may discover that Microsoft makes use of barely totally different terminology inside the Group Coverage setting then they do if you set the execution coverage by means of PowerShell.\n\nSetting the execution coverage from inside PowerShell entails utilizing the Set-ExecutionPolicy cmdlet, adopted by the identify of the coverage that you simply wish to use. There are presently seven totally different execution insurance policies acknowledged by PowerShell. These embrace:\n\n \tAllSigned: All PowerShell scripts should be digitally signed by a trusted writer.\n \tBypass: All scripts are allowed to run, and the person receives no warnings or prompts.\n \tDefault: This setting units the execution coverage to Restricted for Home windows consumer computer systems, and to RemoteSigned for Home windows Server machines.\n \tRemoteSigned: If a script has been downloaded from the Web, then it should be signed by a trusted writer.\n \tRestricted: No PowerShell scripts are allowed to run.\n \tUndefined: No execution coverage is outlined for the given scope. If the execution coverage is ready to Undefined for all scopes, then the efficient coverage shall be Restricted.\n \tUnrestricted: All scripts are allowed to run.\n\nBy default, the Flip On Script Execution Group Coverage setting just isn\u2019t configured, which permits the execution coverage to be managed on a per-machine foundation. Conversely, for those who disable this coverage, then it does primarily the identical factor as setting the PowerShell execution coverage to Restricted.\n\nEnabling the Flip On Script Execution coverage means that you can select between three totally different execution coverage choices. The Enable Solely Signed Scripts choice causes the AllSigned execution coverage for use. Selecting the Enable Native Scripts and Distant Signed Scripts setting units the execution coverage to RemoteSigned. Likewise, selecting the Enable All Scripts choice units the execution coverage to Unrestricted.\nPowerShell execution insurance policies: What\u2019s the profit?\nIt\u2019s simple to imagine that the first (and probably solely) profit to managing PowerShell execution insurance policies on the Group Coverage degree is that doing so allows you to centrally handle PowerShell safety. Whereas that is certainly a compelling profit, there\u2019s one other main benefit of making use of PowerShell execution insurance policies by means of Group Coverage. Check out the screenshot under.\n\nAs you\u2019ll be able to see within the screenshot, I set the Flip On Script Execution coverage to Disabled. From there, I opened an administrative PowerShell session after which used the GPUpdate \/Drive command to use the newly configured Group Coverage setting. I then verified that the execution coverage had been set to Restricted after which used the Set-ExecutionPolicy command to set the execution coverage to Unrestricted. At first, it appears to be like as if PowerShell goes to permit the change. Nevertheless, PowerShell then informs me that my change is overridden by a coverage that\u2019s outlined at a extra particular scope (specifically the Group Coverage). So regardless that I\u2019m logged in as a website admin and am utilizing an administrative PowerShell session, PowerShell blocks my try to set a brand new execution coverage.\n\nIn case you\u2019re questioning, PowerShell additionally blocks any try to carry out a scope degree coverage override. Within the screenshot under, I listed the execution insurance policies which are in impact for every scope after which tried to vary the coverage for a selected scope. Upon doing so, PowerShell produced an error. The identical factor occurs if I attempt to set the execution coverage to Bypass.\n\nAs you\u2019ll be able to see, setting the execution coverage on the Group Coverage degree can significantly improve your group\u2019s safety, as a result of even directors are prohibited from making adjustments to, or bypassing the PowerShell execution coverage. Even so, it is very important perceive that execution insurance policies should not the be-all, end-all of PowerShell safety.\n\nThere are a selection of strategies that can be utilized to bypass PowerShell\u2019s execution coverage. Instruments exist, for instance, that may flip a PowerShell script into an executable file. PowerShell execution insurance policies don\u2019t apply to .EXE information, so the code is allowed to run no matter any execution insurance policies which will exist.\n\nA less complicated technique entails a person or administrator merely operating a script\u2019s instructions separately (by pasting them into the command immediate) reasonably than operating the precise script.\n\nMy level is that setting a restrictive execution coverage just isn\u2019t a assure that PowerShell will stay safe. It\u2019s due to this fact vital to observe protection in depth. Execution insurance policies are an vital safety device, however they have to be used along with different safety mechanisms reminiscent of restrictive permissions and PowerShell logging.