The extension for the PowerShell script is the “.ps1”. It helps to identify the files that have PowerShell code, which helps the PowerShell interpreter recognize and execute them as scripts. Primarily, a script is a plain text file that contains one or more PowerShell commands having the “.ps1” extension. Creating scripts helps the users to use the code later. The scripts can be shared with other PowerShell users easily.
This write-up will cover details about the PowerShell script extension.
What is the PowerShell Script Extension?
The script in PowerShell can be created by saving a text file with a “.ps1” extension. Generally, PowerShell scripts are created using the Windows “PowerShell ISE” program in Windows. PowerShell scripts can be executed using both the “PowerShell” interpreter and the “PowerShell ISE”.
Let’s first create a PowerShell script and save it with the “.ps1” extension
Example 1: Create a PowerShell Script Using Notepad
This example will create a PowerShell script and save it with the “.ps1” extension:
After adding a PowerShell script code, press “CTRL+S” to save the file.
Now, write the desired name and add the “.ps1” extension. Then, select “All Files” from the “Save as type” drop-down:
Let’s verify whether the PowerShell script was created or not:
In the above code snippet:
First, write the “Get-Content” cmdlet and assign the file path:
It can be observed the PowerShell script has been created with the defined content.
Example 2: Create a PowerShell Script Using PowerShell ISE
This illustration will create a PowerShell script using the “PowerShell ISE” and save it with the “.ps1” extension. For that reason, first launch the “PowerShell ISE” from the “Start menu” and write the PowerShell command:
Now, add the script file name in the “File name” section and select the “.ps1” extension from the “Save as type” section:
Let’s verify the creation of the script by executing it:
As you can see, the created script has been created successfully.
Conclusion
PowerShell scripts have the “.ps1” extension. A PowerShell script is simply a plain text file that has the PowerShell cmdlets. These scripts are a great source to save the cmdlets for later use. Moreover, PowerShell scripts can be shared with other PowerShell users. This blog has given details about the PowerShell extension “.ps1” and the method to create and execute it.