How to create and run a PowerShell script file on Windows 10

In this article, TipsMake will guide you how to create and run a PowerShell script file on Windows 10.

PowerShell is a command line tool designed by Microsoft to run commands and scripts to change settings or automate tasks. It sounds like Command Prompt. However, PowerShell is a more functional command line interface (CLI) with a variety of toolkits and flexible control and control capabilities. 

While Command Prompt is only available on Windows, PowerShell is available on Windows, macOS, and Linux.

To create and run a PowerShell script file on Windows 10, follow these steps:

How to create a PowerShell script file

On Windows 10, you can virtually create a PowerShell script file using any text editor or ISE (Integrated Scripting Environment). However, it's best to use the Visual Sturio Code editor with the PowerShell extension.

Visual Studio Code - also known as VS Code - is a free and extensible cross-platform code editor. With VS Code, we can compose and edit almost any kind of programming language. And when you add the PowerShell extension, you'll have a fully interactive scripting experience.

So, the first thing you need to do is download and install VS Code:

  1. Visit Microsoft's VS Code download page here.
  2. Click the Windows button to download the installer
  3. Double click the left mouse button on the downloaded file to run the VS Code installer
  4. Agree to the terms and conditions
  5. Click Next
  6. Click Next again
  7. Click Next for the third time
  8. Confirm additional actions
  9. Click Next
  10. Click Install
  11. Wait for the loader to finish and click Finish

After downloading and installing VS Code, you need to install the PowerShell extension. Here's how to do it:

  1. Open VS Code
  2. Click the Extensions tab on the left side or click Ctrl + Shift + X
  3. Search for PowerShell and click on the first result
  4. Click the Install button

How to create and run a PowerShell script file on Windows 10 Picture 1

When you're done, you can start writing the PowerShell script file using VS Code:

  1. Open VS Code
  2. Click the File menu and choose New File
  3. Click the File menu and choose Save as
  4. In the File name field , name the file with the .ps1 extension , for example make tech easier.
  5. Click Save

How to create and run a PowerShell script file on Windows 10 Picture 2

You can write or paste the script you want to run, for example:

Write-Host "Welcome tipsmake script"

The script above when running will display the following text below the screen:

Welcome tipsmake script

You can run the script by pressing the Run button on the upper right side or pressing the F5 shortcut . After writing the script you should press the File menu and choose Save to save.

After you have finished, your script should be able to run but not execute your commands. This is because by default PowerShell is always set to block any script action. The only exception is when you run the script in VS Code or PowerShell ISE.

How to run a PowerShell script file on Windows 10

To run a script file with PowerShell you need to change the execution policy on Windows 10. 

On Windows 10, PowerShell includes 4 enforcement policies including:

  1. Restricted - Do not allow any scripts to run
  2. RemoteSigned - Allows you to run scripts created on the device but block scripts created on other computers unless they are signed by a trusted entity.
  3. AllSigned - All scripts will run when they are signed by a trusted entity
  4. Unrestricted - Run any script on the computer, without any restrictions

Here's how you set up to run PowerShell scripts on Windows 10:

  1. Press Windows to open the Start menu
  2. Type powershellthen right-click on the search results to run  PowerShell as Administrator
  3. In the PowerShell window , enter the following command and then press Enter :
Set-ExecutionPolicy RemoteSigned
  1. Type A and press Enter

How to create and run a PowerShell script file on Windows 10 Picture 3

  1. Next, you use the following command to run the script. Remember to change the path and filename of the script file to suit your needs:
& "C:/PATHTOSCRIPT/tipsmake_script.ps1"

Above is how to create and run PowerShell script files on Windows 10. Wish you success and invite you to read more great tips on our site.

4 ★ | 1 Vote

May be interested

  • 10 tips with PowerShell in Windows Server 2008 - Part 110 tips with PowerShell in Windows Server 2008 - Part 1
    in fact, there are a lot of windows server 2008 tasks that we can do a lot faster with powershell than the gui-based application or tool. in the following article, we will introduce you some basic and most frequently used operations with powershell ...
  • Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 11Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 11
    part 10 of this article series showed how to use powershell scripts in conjunction with smo and parameters to create sql server scripts. in this section, we will show you how to use powershell cmdlets in conjunction with the sql server client and output saving to export to a text file or xml file.
  • About PowerShellAbout PowerShell
    windows powershell is a command line utility and new scripting language provided by microsoft. why should i study and care about powershell? because it is a new-style utility? of course, every new utility is claimed to be 'different' from the old ones, but powershell has some components that really distinguish it from other utilities.
  • What is Windows PowerShell? How to use Windows PowerShellWhat is Windows PowerShell? How to use Windows PowerShell
    do you want to learn the features of windows powershell but don't know how? suggestions for you what is windows powershell? the most convenient way to use windows powershell.
  • Instructions on how to use PowerShell in Windows Server 2012Instructions on how to use PowerShell in Windows Server 2012
    what is powershell? windows powershell is a command-line shell language interpreter and scripting language specifically designed for system administrators. built on the .net framework, windows powershell helps it professionals control and automate windows operating system administration tasks as well as applications running on windows server environments.
  • What to do when Windows can't find PowerShell?What to do when Windows can't find PowerShell?
    powershell is a handy tool that allows you to automate tasks, fix various errors, and manage several windows installations. but what if it suddenly disappears from your computer?
  • How to add 'Edit or Run with' to the right-click menu of PS1 filesHow to add 'Edit or Run with' to the right-click menu of PS1 files
    a ps1 file is a script or cmdlet, used by windows powershell. this tutorial will show you how to add or remove a custom edit or run with menu to the context menu for powershell .ps1 files for all users in windows 10.
  • 10 tips with PowerShell in Windows Server 2008 - Part 210 tips with PowerShell in Windows Server 2008 - Part 2
    in the previous article, i have shown you some of the basic functions and tricks that can be done with powershell in windows server 2008. and this time, we will continue with part 2, which is also the end. in powershell series in windows server environment ...
  • Test SQL Server with Windows PowerShell - Part 7Test SQL Server with Windows PowerShell - Part 7
    in this section, i will show you how to get that information in top 10 queries based on cpu performance.
  • Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 9Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 9
    in part 9 of this series, i will show you how to use powershell in conjunction with smo to create a sql server script. creating sql server scripts is an important task for administrators and sql server database development professionals.