In this tutorial, I will show you how to run your first Hello World PowerShell script.
Setup
- Install PowerShell.
- Set security policy to enable the execution of PowerShell script.
- Open Run command or console ( Win + R ).
- Type in gpedit.msc to open the Local Group Policy Editor.
- Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > Windows Components > Windows Powershell
- Enable Turn on Script Execution and set your desired Execution Policy. For simplicity, I set mine to Allow all scripts.
Hello World
Open the Command Prompt and then run powershell.exe command. It will open the PowerShell console. Execute the following command to print Hello World.
# Display Hello World on your screen. Write-Host "Hello World"
Output
Or, you can save that command in a file, e.g. hello-world.ps1. Then, execute it as follows:
.\hello-world.ps1
To get out of the console, run the exit command.