Enabling PowerShell Scripts in Windows 10: A Beginner’s Guide

PowerShell lets you run commands and scripts on Windows 10 to modify settings and automate tasks, etc. But the question that you may ask yourself is how do I enable a PowerShell script in Windows 10. To define PowerShell, we should mention that it is a management tool and powerful Windows automation which you can control and automate any part of Windows procedure. Unlike Command Prompt, PowerShell can be used across all platforms like Windows, macOS, and Linux. In this article, we are going to tell you how to enable a PowerShell Script in Windows 10?.
What is a Script?
In any programming language, a script is a code that does a specific function or task. It can be short like a single expression or long like a complex algorithm, and it can run directly in the environment of scripting. You can run the code directly in the PowerShell window, or you can run the PowerShell file with the extension.
Policies and Scopes of PowerShell Execution
You can choose from different scripts execution policies optionally. These Policies designed to differentiate different kinds of scripts. There is a list of policies that you can choose from.
Execution Policy | Description |
Default | Sets Windows to the default execution policy (Restricted for Windows and RemoteSigned for Servers). |
Restricted | This is the default execution policy for Windows 10 and 11. You can’t run any PowerShell scripts and PowerShell is set to interactive mode so that you can only run individual commands. |
RemoteSignedThis is the default execution policy for Windows Servers. You can run downloaded PowerShell scripts, but they must be signed by a trusted publisher. Self-written (non-downloaded) PowerShell scripts can run without a signature. | |
AllSigned | You can only run PowerShell scripts from a trusted publisher, regardless of where they come from. |
Unrestricted | You can run unsigned scripts, but you’ll get a warning before trying to run ones that come from the internet. |
Bypass | This is the least strict setting. Run any script with no warnings or prompts. Not recommended for anything other than test machines. |
Undefined | No policy has been implemented, which automatically applies to the Restricted policy. |
Moreover, Scope, which means the place that the policy will be applied, can effect on these policies. In the list below, you can see different scopes.
Scope | Description |
Process | Set the execution policy for the current Windows PowerShell instance. This will discontinue once PowerShell is closed. |
CurrentUser | The execution policy is set for the current user only and stored in the HKEY_CURRENT_USER registry key. |
LocalMachine | Sets the policy for everyone on the machine via a HKEY_LOCAL_MACHINE key. |
MachinePolicy | Configured using Group Policy for all user accounts on the computer. |
UserPolicy | Configured using Group Policy for the current user account. |
How to Enable PowerShell Script Execution on Windows 10
Follow the steps below to enable PowerShell script:
- Hit the Windows Key to enter the Start Menu.
- Type PowerShell.
- Right-click on the PowerShell result.
- Click on Run as Administrator.
- After opening the PowerShell window, perform get-executionpolicy to understand the current execution policy.
- It will say Restricted which means the scripts are blocked.
- In the PowerShell window, perform the set-executionpolicyremotesigned command.
- Write an A next to the confirmation message.
- Hit Enter.
- To Enable PowerShell Scripts, you should change the execution policy.
How to Check Your PowerShell Execution Policy
You must check what execution policy your PC already is before you do anything. It helps after you change for verification purposes. To check your PowerShell Execution policy, follow the steps below:
- Go to the PowerShell.
- Hold Windows + X to enter Start Context Menu.
- Select Windows PowerShell (Admin).
- Enter the PowerShell get execution policy command.
- Type the following in the main PowerShell window: Get-ExecutionPolicy –List
- Hit Enter.
- Check the areas for your current user and local machine to specify the current policy.
How to Set PowerShell Execution Policy to RemoteSigned
You can enable running PowerShell Scripts with the RemoteSigned policy through the setting of Windows. To do so, follow the steps below:
- Hold Windows + I to go to the Settings.
- Select Update & Security.
How to Set the PowerShell Execution Policy to RemoteSigned via Developer Options
- Select For Developers on the left sidebar.
- Scroll down to the subheading of PowerShell.
- Tick the option of change execution policy to allow local PowerShell scripts to run without signing. Require signing for remote scripts.
How to Set the PowerShell Execution Policy for the Current User through PowerShell
You can activate PowerShell scripts through different policy for the current user by the command line. To do so, follow the steps below:
- Type the following command in the PowerShell window:
Set-ExecutionPolicy Bypass -Scope CurrentUser –Force
- Change Bypass for the type of policy that you want to use to enable PowerShell scripts.
How to Enable PowerShell Scripts for the Local Machine through Command Line
It is possible to apply a policy to the machine as a whole through a gradual change to the command.
- Set the current user policy to Undefined (Optional).
Windows will use everything you have chosen for the current user when setting your execution policy for the local machine. It might get an error of “Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope”. You can switch to Undefined or change it separately in the next step if you want the current user to have the same setting. Or, you can ignore this error.
- To activate PowerShell scripts in Windows, use the PowerShell set execution policy command.
You can use two separate commands to set the execution policy for the current Windows user and the Local machine:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Set-ExecutionPolicy Unrestricted -Scope LocalMachine –Force
It is possible to set a policy for each of them or set the current user to Undefined.
How to Create a Script via VS Code
Visual Studio or VS code is a cross-platform code editor which is free and extensible and lets you edit any programming language virtually. You can have an interactive scripting editing experience with IntelliSense support when adding the PowerShell extension. The PowerShell ISE application will be available, but something like Visual Studio Code with the PowerShell extension seems to be a new experience we should mention that the legacy experience does not support PowerShell 7 or higher.
How to Install VS Code
Follow the steps below to install VS code
- Enter the page of Visual Studio Download.
- Select the Windows to download the installer.
- To begin the installer process, double-click the installer.
- Accept the agreement terms.
- Hit Next.
- Confirm additional tasks as necessary.
- Hit Next.
- Select the Install.
- Hit Finish.
How to Install PowerShell Extension
Use the steps below to install the extension of the PowerShell.
- Go to VS Code.
- Select the Extension tab (Ctrl + Shift + X) from the left pane.
- Search for PowerShell, and select the top result.
- Select Install.
- Hit the Trust Workspace & Install button.
How to Create PowerShell Script with Visual Studio Code
Follow the steps below to create a script with Visual Studio Code
- Go to the VS Code.
- Hit the File Menu.
- Click on New File.
- Hit the File Menu.
- Click Save As.
- Specify a name for the file with the .ps1 extension in the File name field. For example, first_script.ps1.
- Select Save.
- Write a new script you want to run — for example, Write-Host “Congratulations! Your first script executed successfully”
Note: the above script will show you the phrase Congratulations on the screen.
- Hit Run from the top-right side or you can press F5 to run the script.
- Select the File Menu.
- Hit Save.
How to Create PowerShell Script with Notepad
Follow the steps below to make a PowerShell Script with the Notepad editor on Windows 10:
- Go to the Start Menu.
- Look for Notepad and click on it.
- Write or paste the new script in the text file. For example, Write-Host “Congratulations! Your first script executed successfully”
- Select the File Menu.
- Click on Save As.
- Input a descriptive name for the script. For example, first_script.ps1.
- Hit Save.
How to Create PowerShell Script with Integrated Scripting Environment
You can use the built-in PowerShell ISE console to code your script on Windows 10. Follow the steps below to get started using these steps:
- Go to Start.
- Look for Windows PowerShell ISE.
- Right click the top result and click on Run as Administrator.
- Select the File Menu.
- Hit New to make a new empty .ps1 file.
- Write or paste the new script in the text file. For example, Write-Host “Congratulations! Your first script executed successfully”
- Select the File Menu.
- Hit Save.
- Input a descriptive name for the script. For example, first_script.ps1.
- Choose the folder location to store the script file.
- Hit Save.
- (Option) From the top-right side, select Run.
Conclusion
In this article, we presented some ways to enable script in Windows 10. From the above methods, which method will you choose? Do you know any other method? Share your answers with us.