Table of Contents
The File is not Digitally Signed
In some cases, you would get the following error when trying to run a PowerShell script downloaded from the internet. In our case, this script to get reporting about mailboxes.
D:\scripts\.\MailboxSizeReport365.ps1
PS C:\> D:\scripts\MailboxSizeReport365.ps1
D:\scripts\MailboxSizeReport365.ps1 : File D:\scripts\MailboxSizeReport365.ps1 cannot be loaded. The file
D:\scripts\MailboxSizeReport365.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ D:\scripts\MailboxSizeReport365.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
When we check the execution policy in our computer. It said the current policy is configured to RemoteSigned. It means the computer is allowed to run scripts that have been create on this computer or be signed.
PS C:\> Get-ExecutionPolicy
RemoteSigned
Solutions
Method 1: Unblock the file downloaded from internet
The first and easiest way to run this script is unblock this file. When a script downloaded from the internet, Windows blocked the files to protect your computer.
You can check it by right-clicking on the file then selecting Properties. As you can see in the below screenshot, the file has been blocked. You can select the unblock checkbox then click OK to unblock it.
Once the file is unblocked, the script should be running without any issues.
Alternatively, you can unblock the file using Unblock-File cmdlet as follows:
Unblobk-File -Path 'D:\scripts\MailboxSizeReport365.ps1'
Method 2: Change the execution policy
The second way, you can change the execution policy on your computer. We use the Bypass policy with Process parameter. This allows your computer to run any scripts in the current session only.
Set-ExecutionPolicy -ExecutionPolicy Bypass Process
As you can see, even the file still blocking, the script can be run without any errors.
PS C:\> Set-ExecutionPolicy -ExecutionPolicy Bypass Process
PS C:\> Get-ExecutionPolicy
Bypass
PS C:\> D:\scripts\.\MailboxSizeReport365.ps1
Mailbox Size Report 365
----------------------------
1.Export to CSV File (OFFICE 365)
2.Enter the Mailbox Name with Wild Card (Export) (OFFICE 365)
Choose The Task:
If you close, then reopen a new PowerShell window. The execution policy would be reverted to RemoteSigned.
Additionally, you can run the below command to allow running any scripts in your computer permanently.
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
When using Unrestricted policy, unsigned scripts can run. There is a risk of running malicious scripts. PowerShell will warn you before running scripts and configuration files that are not from the local intranet zone.
PS C:\> D:\scripts\.\MailboxSizeReport365.ps1
Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
message. Do you want to run D:\scripts\MailboxSizeReport365.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): r
Mailbox Size Report 365
----------------------------
1.Export to CSV File (OFFICE 365)
2.Enter the Mailbox Name with Wild Card (Export) (OFFICE 365)
Choose The Task:
Not a reader? Watch this related video tutorial: