Skip to main content

Fix PowerShell Script execution errors for SharePoint and Microsoft 365 setup

BindTuning Team avatar
Written by BindTuning Team
Updated over 2 months ago

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:

  1. Open PowerShell with Administrator privileges:

    Windows Start menu > PowerShell > Right-click on "Windows PowerShell" (or "PowerShell") and select "Run as Administrator."
    ​

  2. 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.
    ​

  3. Set Execution Policy to Unrestricted:

    To allow scripts to run, execute the following command:

    Set-ExecutionPolicy Unrestricted

  4. Run Your Setup Scripts:
    With the Execution Policy set to Unrestricted, you can now proceed to run your PowerShell solution installation scripts or any other necessary setup scripts.
    ​

  5. 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 or Set-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 the cmd.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.

Did this answer your question?