Table of Contents
The File is Not Digitally Signed You Cannot Run this Script
Sometimes, when attempting to execute a PowerShell script on Windows systems, you may encounter the following error. Even the Execution Policy is configured as RemoteSign.
This occurs because, by default, scripts downloaded from the internet are blocked from execution to protect the system. You can check it by right-clicking on the script and then selecting Properties.
As you can see, in the security section the file is blocked because it came from another computer. To make it executable, uncheck the checkbox then click OK.
Alternatively, from PowerShell you can check if a file is blocked by using the Get-Item cmdlet with the –Stream parameter. If you get an error, it means the file is not blocked.
Get-Item .\Add_Structure.ps1 -Stream "Zone.Identifier"
If the output resembles the one shown below, it indicates that the file is blocked. You will need to unblock it before you can execute it.
PSPath : Microsoft.PowerShell.Core\FileSystem::D:\Run-in-Sandbox\Add_Structure.ps1:Zone.Identifier
PSParentPath : Microsoft.PowerShell.Core\FileSystem::D:\Run-in-Sandbox
PSChildName : Add_Structure.ps1:Zone.Identifier
PSDrive : D
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName : D:\Run-in-Sandbox\Add_Structure.ps1
Stream : Zone.Identifier
Length : 85
To unblock a file using PowerShell, we need the Unblock-File cmdlet.
Unblock-File .\Add_Structure.ps1
Once the file is unblocked, if you check it using the Get-Item cmdlet, you will get as below. It’s expected.
PS D:\Run-in-Sandbox> Unblock-File .\Add_Structure.ps1
PS D:\Run-in-Sandbox> Get-Item .\Add_Structure.ps1 -Stream "Zone.Identifier"
Get-Item : Could not open the alternate data stream 'Zone.Identifier' of the file 'D:\Run-in-Sandbox\Add_Structure.ps1'.
At line:1 char:1
+ Get-Item .\Add_Structure.ps1 -Stream "Zone.Identifier"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (D:\Run-in-Sandbox\Add_Structure.ps1:String) [Get-Item], FileNotFoundExce
ption
+ FullyQualifiedErrorId : AlternateDataStreamNotFound,Microsoft.PowerShell.Commands.GetItemCommand
Finally, use PowerShell to verify that it works.
Not a reader? Watch this related video tutorial: