PowerShell is the scripting language to manage Windows systems. PowerShell commands or cmdlets can be used to create script files which are called PowerShell script. By creating and running the PowerShell script we do not need to type every PowerShell command again and again.
Create PowerShell Script with PowerShell ISE
PowerShell scripts can be created in different ways. The PowerShell ISE is used to develop PowerShell scripts and executed in a feature-rich environment. The PowerShell ISE can be opened from the Start Menu where typing “PowerShell ise”. Start clicking on the listed PowerShell ISE. The default main screen of the PowerShell ISE is like below. The default main screen consists of the Script pane, PowerShell Command-line interface, and Command List. The PowerShell script is typed into the script pane and can be saved as a PowerShell script. Also by using the Run button the script can be executed in the PowerShell command-line interface below.
Just put the PowerShell script into the script pane and use CTRL+S or Save icon in order to save the PowerShell script. The save menu provides the following screen where the name of the script can be specified.
Write-Host "Hello, World!"
We will see the following screen where we will specify the Script name which is “MyScript.ps1”. As we can see the PowerShell script extension is
*.ps1. Then navigate to the path you want to save the PowerShell script. The last step is clicking on “Save“.
Create PowerShell Script with Notepad or Notepad++
PowerShell is a scripting language where the scripts consist of simple text files. There is not binary or property type in order to create a PowerShell script. Just put the commands into a simple text file with the
*.psm1 . Event the file extension can be committed it is the best to use for script files. Below we can see that the script file name is
MyScript.ps1 . We can create a script file by using the Notepad text editor. Alternatively, the
NotePad++ can be used to create a PowerShell script file.
Run PowerShell Script From File Explorer
The File Explorer can be also used to run or execute a PowerShell script. First, open the File Explorer and navigate to the location of the script file. Then right-click to the PowerShell script file where a context menu will be opened. Click to the
Run with PowerShell from this context menu which starts a new PowerShell command-line interface and executes the specified script.
Run PowerShell Script From PowerShell
The PowerShell scripts can be executed or run from the PowerShell command line interface easily. First open the PowerShell command line interface via the Start Menu by typing
powershell . Then navigate to the PowerShell Script path by using the
cd command and path parameters. In the following example the PowerShell script is located under the
Then the MyScript.ps1 PowerShell script is executed like below.
Alternatively the script can be executed by specifying the absolute or complete path like below.