(Image credit: Mauro Huculak)
On Windows 11 (or 10), PowerShell is a command-line interface (CLI) to run commands and scripts to automate tasks and change settings on your device, similar to Command Prompt. However, PowerShell is a more powerful CLI, offering more tools and flexibility. In addition, unlike Command Prompt, PowerShell is available across platforms, including Windows, macOS, and Linux.
A script is a collection of instructions written to a text file (using the “.ps1” extension) that PowerShell understands and executes in sequence to run different actions.
The only caveat is that the default security protocol prevents scripts from running on your computer. This means that when double-clicking a “.ps1” file, the system won’t do anything, and if you try to run the script within PowerShell, you will see the “cannot be loaded because running scripts is disabled on this system” error message. However, running scripts on your device is possible. You only need to enable the correct execution policy.
In this how-to guide, I will walk you through the steps to create and run your first script file on PowerShell using Visual Studio Code, Notepad, and the PowerShell Integrated Scripting Environment (ISE) console, whether you use Windows 10 or 11.
How to create PowerShell script file on Windows 11 and 10
It’s possible to create PowerShell script files using any text editor or the legacy ISE application. However, the Visual Studio Code editor is the preferred option for writing scripts moving forward.
Create a script with VS Code
Visual Studio Code (VS Code) is a free, extensible, cross-platform code editor that works to write virtually any programming language. And when adding the PowerShell extension, you get an interactive scripting editing experience, which even comes with IntelliSense (code-completion) support.
You can still use PowerShell ISE, but Visual Studio Code with the PowerShell extension is meant to be the new default experience. Also, consider that the legacy experience won’t get any new features and doesn’t support PowerShell 7 or future releases.
All the latest news, reviews, and guides for Windows and Xbox diehards.
Install VS Code
To install Visual Basic Code on Windows 11 (or 10), use these steps:
Once you complete the steps, you can continue installing the PowerShell extension for VS Code.
Install PowerShell extension
To install the PowerShell extension on VS Code, use these steps:
After you complete the steps, you can start writing PowerShell scripts from Visual Studio Code.
Create PowerShell script with Visual Studio Code
To create a script with Visual Basic Code on Windows 11 (or 10), use these steps:
Create PowerShell script with Notepad
To create a PowerShell script with the Notepad app, use these steps:
Create PowerShell script with Integrated Scripting Environment
You can also use the built-in PowerShell ISE app to code your scripts on Windows.
The Integrated Scripting Environment (ISE) is a complex tool, but you can get started using these easy steps:
How to run PowerShell script file on Windows 11 and 10
Whether you use Windows 11 or 10 on your computer, you must change the execution policy to run a script with PowerShell.
To change the execution policy to run PowerShell scripts on Windows 11 (or 10), use these steps:
After you complete the steps, the script will run, and if it was written correctly, you should see its output on the screen without issues.