Operating System

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 PolicyDescription
DefaultSets Windows to the default execution policy (Restricted for Windows and RemoteSigned for Servers).
RestrictedThis 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. 
AllSignedYou can only run PowerShell scripts from a trusted publisher, regardless of where they come from.
UnrestrictedYou can run unsigned scripts, but you’ll get a warning before trying to run ones that come from the internet.
BypassThis is the least strict setting. Run any script with no warnings or prompts. Not recommended for anything other than test machines.
UndefinedNo 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.

ScopeDescription
ProcessSet the execution policy for the current Windows PowerShell instance. This will discontinue once PowerShell is closed.
CurrentUserThe execution policy is set for the current user only and stored in the HKEY_CURRENT_USER registry key.
LocalMachineSets the policy for everyone on the machine via a HKEY_LOCAL_MACHINE key.
MachinePolicyConfigured using Group Policy for all user accounts on the computer.
UserPolicyConfigured 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:

  1. Hit the Windows Key to enter the Start Menu.
  2. Type PowerShell.
  3. Right-click on the PowerShell result.
  4. Click on Run as Administrator.
  5. After opening the PowerShell window, perform get-executionpolicy to understand the current execution policy.
  6. It will say Restricted which means the scripts are blocked.
  7. In the PowerShell window, perform the set-executionpolicyremotesigned command.
  8. Write an A next to the confirmation message.
  9. Hit Enter.
  10. 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:

  1. Go to the PowerShell.
  2. Hold Windows + X to enter Start Context Menu.
  3. Select Windows PowerShell (Admin).
  4. Enter the PowerShell get execution policy command.
  5. Type the following in the main PowerShell window: Get-ExecutionPolicy –List
  6. Hit Enter.
  7. 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:

  1. Hold Windows + I to go to the Settings.
  2. Select Update & Security.

How to Set the PowerShell Execution Policy to RemoteSigned via Developer Options

  1. Select For Developers on the left sidebar.
  2. Scroll down to the subheading of PowerShell.
  3. 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:

  1. 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.

  1. 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

  1. Enter the page of Visual Studio Download.
  2. Select the Windows to download the installer.
  3. To begin the installer process, double-click the installer.
  4. Accept the agreement terms.
  5. Hit Next.
  6. Confirm additional tasks as necessary.
  7. Hit Next.
  8. Select the Install.
  9. Hit Finish.

How to Install PowerShell Extension

Use the steps below to install the extension of the PowerShell.

  1. Go to VS Code.
  2. Select the Extension tab (Ctrl + Shift + X) from the left pane.
  3. Search for PowerShell, and select the top result. 
  4. Select Install.
  5. 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

  1. Go to the VS Code.
  2. Hit the File Menu.
  3. Click on New File.
  4. Hit the File Menu.
  5. Click Save As.
  6. Specify a name for the file with the .ps1 extension in the File name field. For example, first_script.ps1.
  7. Select Save.
  8. 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:

  1. Go to the Start Menu.
  2. Look for Notepad and click on it.
  3. Write or paste the new script in the text file. For example, Write-Host “Congratulations! Your first script executed successfully”
  4. Select the File Menu.
  5. Click on Save As.
  6. Input a descriptive name for the script. For example, first_script.ps1.
  7. 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:

  1. Go to Start.
  2. Look for Windows PowerShell ISE.
  3. Right click the top result and click on Run as Administrator.
  4. Select the File Menu.
  5. Hit New to make a new empty .ps1 file.
  6. Write or paste the new script in the text file. For example, Write-Host “Congratulations! Your first script executed successfully”
  7. Select the File Menu.
  8. Hit Save.
  9. Input a descriptive name for the script. For example, first_script.ps1.
  10. Choose the folder location to store the script file.
  11. Hit Save.
  12. (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.

Reyhane A

Reyhane is an author and technology enthusiast who has a passion for writing about Windows tips and tricks. Born and raised in Tehran, Iran, Reyhane always had an interest in technology, which led her to pursue a degree in computer engineering from the University of Tehran. After completing her studies, Reyhane began working as a software engineer, where she gained a wealth of experience and knowledge in the field of technology. She soon discovered her love for writing, and began sharing her knowledge with others through her blog. Reyhane's blog quickly gained popularity, and she became known as an expert in the field of Windows tips and tricks. Her articles are known for being clear, concise, and easy to understand, making them accessible to everyone, regardless of their level of technical expertise. Today, Reyhane continues to share her knowledge with the world through her blog and YouTube channel, where she provides tips and tricks for Windows users to help them optimize their computer's performance and get the most out of their technology. In addition to her passion for technology, Reyhane enjoys traveling, photography, and spending time with her family and friends. She is also an avid reader and is always on the lookout for new books to add to her collection. Reyhane's dedication to her work and her love for technology have made her a respected figure in the industry, and she continues to inspire and educate others through her writing and online content.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button