PowerShell - Hello World

By xngo on January 5, 2020

In this tutorial, I will show you how to run your first Hello World PowerShell script.

Setup

  1. Install PowerShell.
  2. Set security policy to enable the execution of PowerShell script.
    1. Open Run command or console ( Win + R ).
    2. Type in gpedit.msc to open the Local Group Policy Editor.
    3. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > Windows Components > Windows Powershell
    4. Enable Turn on Script Execution and set your desired Execution Policy. For simplicity, I set mine to Allow all scripts.
      MS Windows - Security Policy - Turn on Script Execution

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

PowerShell - 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.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.