When setting up or configuring SharePoint environments (including SharePoint Online) or other Microsoft 365 services, running PowerShell scripts is often a necessary step. However, it's common to find issues, particularly errors related to script execution permissions. This article guides you through resolving two of the most frequent issues: the "scripts disabled" error and "Access Denied" messages.
Understanding the "Scripts are disabled" error
One of the most common errors you might see when running a PowerShell script is:
File C:\Common\Scripts\YourScript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
This message indicates that your system's PowerShell Execution Policy is preventing scripts from running. The Execution Policy is a security feature that controls the conditions under which PowerShell loads configuration files and runs scripts. By default, it might be set to a restrictive level, preventing unsigned or downloaded scripts from executing.
How to enable PowerShell Script execution
To overcome the "scripts are disabled" error, you need to temporarily adjust your PowerShell Execution Policy. Follow these steps:
Open PowerShell with Administrator privileges:
Windows Start menu > PowerShell > Right-click on "Windows PowerShell" (or "PowerShell") and select "Run as Administrator."
βCheck your current Execution Policy, type and press Enter:
Get-ExecutionPolicy
Note down the current policy (e.g.,
Restricted
,RemoteSigned
, etc.) as you might want to revert to it later.
βSet Execution Policy to Unrestricted:
To allow scripts to run, execute the following command:
Set-ExecutionPolicy Unrestricted
Run Your Setup Scripts:
With the Execution Policy set toUnrestricted
, you can now proceed to run your PowerShell solution installation scripts or any other necessary setup scripts.
βOptionally Revert Execution Policy: Once your scripts have successfully completed, it's a good practice to revert your Execution Policy to its original, more secure setting. Use the policy you noted down in Step 2:
Set-ExecutionPolicy [OldPolicy]
Replace
[OldPolicy]
with the value you recorded (e.g.,Set-ExecutionPolicy Restricted
orSet-ExecutionPolicy RemoteSigned
).
Important Security Note: Setting the Execution Policy to Unrestricted allows all scripts to run, regardless of their source or signature. While necessary for some setup processes, it can pose a security risk. It's generally recommended to revert to a more secure policy (like RemoteSigned) after you have successfully run your required setup scripts.
Resolving "Access Denied" messages
Sometimes, even after adjusting the Execution Policy, you might encounter an "Access Denied" message. This typically indicates that the command-line interface itself (PowerShell or Command Prompt) does not have the necessary administrative permissions to perform the requested action. To fix this:
Always Run as Administrator: Ensure that any command-line prompt you are using to execute scripts or commands (whether it's PowerShell or the classic
cmd.exe
) is opened with administrative privileges.For
cmd.exe
: If you are running scripts directly from the Windows Command Prompt (cmd.exe
), right-click on thecmd.exe
shortcut or executable and choose "Run as Administrator" before attempting to execute your scripts.
This simple step often resolves permission-related errors that prevent script execution.