How to Make A PowerShell Script in Windows 11 (With Example)
Creating a PowerShell script in Windows 11 involves several essential steps. First, you need to understand what PowerShell does and how it interprets commands. PowerShell works with cmdlets, which are lightweight commands designed to perform specific functions. These cmdlets follow a Verb Noun format, such as Get Process, Set Location, or New Item.
When you write multiple commands in a single file and save it as a .ps1 file, it becomes a reusable script. You can execute that script to perform multiple tasks automatically without typing each command manually.
Windows 11 includes Windows PowerShell 5.1 by default, and many users also install PowerShell 7, which is a cross-platform and updated version. Both versions support creating and running scripts.
To successfully create and run a PowerShell script, you need to do the following:
- Understand basic PowerShell syntax
- Use a text editor to write commands
- Save the file correctly
- Set the appropriate execution policy
- Run the script
In this complete guide, you will learn how to create, write, save, and run a PowerShell script step by step, along with best practices and answers to common questions.
How to Make A PowerShell Script in Windows 11?

To make a PowerShell script in Windows 11, open a text editor such as Notepad, write your PowerShell commands, and save the file with a .ps1 extension. Then adjust the execution policy if necessary and run the script using Windows PowerShell or PowerShell 7.
Now, let us go through each step in detail.
Step 1: Open a Text Editor in Windows 11
The first step in creating a PowerShell script is choosing a text editor. You can use Notepad, which is pre-installed in Windows 11, or more advanced editors such as Visual Studio Code.
For beginners, Notepad is simple and sufficient.
To open Notepad in Windows 11, press the Windows key, type Notepad, and press Enter. A blank text file will appear on your screen.
This file will be used to write your PowerShell commands.
If you prefer a more advanced tool, you can install Visual Studio Code from the official website of Microsoft. Visual Studio Code provides syntax highlighting and debugging features, which are helpful when writing complex scripts.
For now, we will continue using Notepad to keep things simple.
Step 2: Write Your First PowerShell Command
Once Notepad is open, you can begin writing PowerShell commands.
Let us start with a simple example. Type the following command in Notepad:
Write-Output “Hello, World!”
This command uses the ‘Write-Output cmdlet’ to display text on the screen.
You can also try another example that retrieves system information:
Get ComputerInfo
This cmdlet displays detailed information about your Windows 11 system.
Each line in your script represents a command. PowerShell will execute them sequentially from top to bottom.
You can write multiple commands like this:
Write-Output “Welcome to PowerShell Scripting”
Get Date
Get Process
The Get Date cmdlet displays the current date and time, while Get Process shows running processes.
Understanding how cmdlets work is important because they are the building blocks of every PowerShell script.
Step 3: Add Comments to Your Script
Comments are lines in a script that explain what the code does. They are ignored during execution.
In PowerShell, comments begin with the hash symbol.
For example:
This script displays a welcome message: Write Output “Hello from Windows 11”
Adding comments makes your script easier to understand, especially if you share it with others or revisit it later.
Good documentation is a best practice in scripting and programming.
Step 4: Save the File as a .ps1 Script
After writing your commands, the next step is saving the file correctly.
Click on File in Notepad and select Save As. In the File name field, type a name followed by the .ps1 extension. For example:
myscript.ps1
In the Save as type dropdown menu, choose All Files instead of Text Documents. This step is very important because if you leave it as Text Documents, Notepad will save the file as myscript.ps1.txt, which will not work as a PowerShell script.
Choose a location, such as Desktop or Documents, and click Save.
Your PowerShell script is now created.
Step 5: Configure PowerShell Execution Policy
By default, Windows 11 may restrict running scripts for security reasons. This restriction is controlled by the Execution Policy.
To check your current execution policy, open PowerShell.
Press the Windows key, type PowerShell, right-click on Windows PowerShell, and select Run as administrator.
In the PowerShell window, type:
Get ExecutionPolicy
If the result is Restricted, scripts will not run.
To allow local scripts to run, type:
Set ExecutionPolicy RemoteSigned
Press Enter and confirm by typing Y.
The RemoteSigned policy allows scripts created on your computer to run while requiring downloaded scripts to be digitally signed.
Be careful when changing execution policies, as running untrusted scripts can pose security risks.
Step 6: Run the PowerShell Script
Now that your script is saved and the execution policy is configured, you can run the script.
Open PowerShell and navigate to the folder where your script is saved.
For example, if it is on your Desktop, type:
cd Desktop
Then run the script by typing:
.\myscript.ps1
The dot and backslash indicate that the script is in the current directory.
Press Enter, and your script will execute. You will see the output displayed in the PowerShell window.
If there are errors, PowerShell will display error messages that help you identify and fix issues.
How to Save a PowerShell Script?
Saving a PowerShell script properly ensures it runs without issues.
First, always use the .ps1 extension. This tells Windows that the file is a PowerShell script.
Second, select All Files in the Save As dialog box when using Notepad. This prevents the file from being saved as a text file.
Third, store scripts in an organized folder such as Documents\PowerShellScripts. This helps you manage multiple scripts efficiently.
If you are using Visual Studio Code, click File and then Save As, enter the file name with the .ps1 extension, and choose the desired location.
You can also edit existing scripts by right-clicking the file and selecting Edit. This opens the script in Notepad or your default text editor.
FAQs
What is a PowerShell script?
A PowerShell script is a text file containing a sequence of PowerShell commands saved with a .ps1 extension. It allows users to automate tasks in Windows 11.
Is PowerShell available in Windows 11 by default?
Yes, Windows 11 includes Windows PowerShell 5.1 by default. Users can also install PowerShell 7 for additional features and improvements.
Why is my PowerShell script not running?
Your script may not run due to the execution policy being set to Restricted. Use the Get ExecutionPolicy cmdlet to check the policy and Set ExecutionPolicy RemoteSigned to allow local scripts.
What is the difference between PowerShell and Command Prompt?
PowerShell is more advanced than the Command Prompt. It supports scripting, automation, object-based output, and advanced system administration tasks.
Can I edit a PowerShell script after saving it?
Yes, you can right-click the .ps1 file and choose Edit to modify it. After editing, save the file again and run it.
Is it safe to run PowerShell scripts?
It is safe to run scripts you create yourself. However, be cautious when running scripts downloaded from the internet. Always verify the source before execution.
