Home Blog Why PowerShell Scripts May Hang Or Execute With Delay

Why PowerShell Scripts May Hang Or Execute With Delay

Sometimes, you may notice that scripts seem to hang, and after you had a coffee, seem to run again.

The same may occur with the ISESteroids script fixer feature because it, too, internally runs a series of scripts.

Signed Scripts Are Checked Online

The reason can be a digital signature that is present in your script. Digital signatures are good because they help you identify who created a script, and whether it is untouched. Digital signatures appear as comment block at the end of a script.

However, there is a dark side to it, too. When you run a digitally signed script, Windows tries to check whether the signature is valid. If your computer has a network connection, Windows will try and get a certificate revocation list to see if the signer is valid.

Only, it will never get that list if your computer has no Internet connection. Windows will keep trying for a very-long-time, causing a major delay during which ISE appears to be hanging.

Disabling Signature Check

The automatic signature check is tied to PowerShells execution policy. Any execution policy except “Bypass” will trigger the signature check.

So one easy workaround is to have PowerShell not check digital signatures automatically. Simply set the PowerShell execution policy to “Bypass” (not “Unrestricted”). This will turn off all automatic checks, and run the scripts you want to run – immediately.

To be clear: changing the execution policy to “Bypass” will not enable attackers contact your system. This would be the resposibility of a firewall. The execution policy is just your own personal seat belt that typically helps you identify scripts that come from an untrusted source. Disabling the execution policy will no longer warn you if you try and run a script that came as email attachment. Then again, as an Administrator, you should know what you are doing. Execution policy is most useful for inexperienced users.

Here is how you can change your personal execution policy to “Bypass” and disable automatic certificate checks:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force

To undo the change, clear your setting:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Undefined -Force


Using a Trick

If you cannot apply your execution policy because there is another policy at domain level that overrides your personal preference, then here is a clever trick:

In ISESteroids, you can always open the menu “Debug”, then choose “Advanced”, and check “Execution Policy Override”. This will turn off execution policy for this session, no matter what. This bail out is available in ISESteroids only. It’s not available in plain ISE.