Skip to main content

Hello World (first programs) · Beginner · 16 min

Hello World in PowerShell 7 on Windows, Linux and macOS

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · PowerShell 7.6.10 LTS (.NET 10)

You will install PowerShell 7.6 LTS, print Hello World in the pwsh shell and from a saved script, add a parameter with a default value and pass file objects through a pipeline.

On this page

PowerShell is a shell and scripting language from Microsoft. The thing that sets it apart from Bash or the Windows Command Prompt is what flows between commands. In Bash, one command prints text and the next one has to cut that text apart. In PowerShell, commands pass .NET objects: a file arrives as a file object with a Name, a Length and a LastWriteTime, so the next command asks for the property it wants instead of guessing which column holds it.

Commands follow a verb-noun naming pattern: Get-ChildItem, Set-Location, New-Item, Write-Output. Built-in commands like these are called cmdlets (say "command-lets"). Once you know the pattern, you can often guess a command's name before you look it up.

There are two PowerShells, and beginners mix them up:

  • Windows PowerShell 5.1 comes with Windows. Its program is powershell.exe, it runs on the older .NET Framework, it only runs on Windows, and it now gets security fixes but no new features.
  • PowerShell 7 is the current, open-source version. Its program is pwsh, it runs on modern .NET, and it runs on Windows, Linux and macOS. It installs next to 5.1 and does not replace it.

This tutorial uses PowerShell 7.6.10, the current long-term support (LTS) release, built on .NET 10 and supported until 14 November 2028. PowerShell 7.7 came out on 10 November 2026, but it is a standard release with a shorter support window, and some package managers already install it by default. Everything in this tutorial works the same on 7.7.

PowerShell is used for Windows Server and Active Directory administration, managing Microsoft 365 and Exchange Online, automating Azure, and for cross-platform scripts that run unchanged on Windows, Linux and macOS build agents. If you work in IT support or security on Windows networks, you will meet it daily.

Step 1 · Install PowerShell 7

On Ubuntu 26.04

Microsoft's own package repository for Ubuntu 26.04 only carries the newest stable release, and only for Intel and AMD (x86_64) machines. To get the 7.6 LTS release on both x86_64 and Arm machines, download the .deb package from the PowerShell release page and check it against the checksum file that the release publishes. The download is roughly 50 MB, which is worth knowing if you are on prepaid mobile data.

Bash
sudo apt update
sudo apt install -y curl ca-certificates
VERSION=7.6.10
ARCH="$(dpkg --print-architecture)"
DEB="powershell_${VERSION}-1.deb_${ARCH}.deb"
mkdir -p ~/pwsh-install && cd ~/pwsh-install
curl -fsSLO "https://github.com/PowerShell/PowerShell/releases/download/v${VERSION}/${DEB}"
curl -fsSLO "https://github.com/PowerShell/PowerShell/releases/download/v${VERSION}/hashes.sha256"
iconv -f UTF-16 -t UTF-8 hashes.sha256 | tr -d '\r' | grep -F " *${DEB}" | sha256sum -c -

Line by line: dpkg --print-architecture prints amd64 or arm64, which picks the right file. The release's hashes.sha256 is saved in UTF-16 with Windows line endings, so iconv and tr turn it into plain text before grep picks out the line for your file and sha256sum -c checks it. The last command must print powershell_7.6.10-1.deb_amd64.deb: OK (or arm64). If it prints FAILED, stop and download again.

Install the package. Giving apt a path that starts with ./ makes it install a local file and pull in the libraries PowerShell needs:

Bash
sudo apt install -y "./${DEB}"
cd ~ && rm -rf ~/pwsh-install
pwsh --version

apt may print a note that the download was "performed unsandboxed as root". That is harmless for a local file. A package installed from a file gets no updates from apt upgrade; the last step shows how to upgrade.

PowerShell sends basic usage data to Microsoft when it starts. To turn that off, set the environment variable POWERSHELL_TELEMETRY_OPTOUT=1 before you start it, for example by adding export POWERSHELL_TELEMETRY_OPTOUT=1 to your ~/.profile.

On Windows 10 or 11

Open Windows Terminal or the old Windows PowerShell window and run:

PowerShell
winget install --id Microsoft.PowerShell --source winget

This installs the newest stable release, which is 7.7 at the time of writing. If your organisation standardises on the LTS, download PowerShell-7.6.10-win-x64.msi (or -win-arm64.msi) from the v7.6.10 release on github.com/PowerShell/PowerShell instead. Afterwards, open a new terminal tab and choose PowerShell (not Windows PowerShell), or type pwsh.

On macOS

With Homebrew installed, run:

Bash
brew install powershell

The Homebrew formula is maintained by the Homebrew community and tracks the newest stable release. For the LTS build from Microsoft, download powershell-7.6.10-osx-arm64.pkg from the v7.6.10 release page and open it.

Check it worked

pwsh --version prints PowerShell 7.6.10 (or PowerShell 7.7.0 if winget or Homebrew installed the newer stable release).

Step 2 · Say hello in the interactive shell

Start PowerShell by typing pwsh in your terminal. The prompt changes to something like PS /home/you> on Linux or PS C:\Users\you> on Windows. The PS tells you that you are now typing PowerShell, not Bash or cmd.

Type your first command:

PowerShell
Write-Output "Hello, World!"

Write-Output is a cmdlet: the verb Write and the noun Output. It sends its argument, the text in double quotes, down the pipeline. With nothing after it in the pipeline, PowerShell prints what arrives, so you see Hello, World!.

Now type only the text:

PowerShell
"Hello, World!"

It prints the same line. A value on its own in PowerShell is output, and that is why many scripts never call Write-Output at all. Ask PowerShell which version is running:

PowerShell
$PSVersionTable.PSVersion

$PSVersionTable is a built-in variable (all variables start with $), and .PSVersion reads one of its properties. PowerShell prints it as a small table with Major, Minor and Patch columns.

To see the verb-noun pattern at work, list every command whose noun is Item:

PowerShell
Get-Command -Noun Item

You get Clear-Item, Copy-Item, Get-Item, Move-Item, New-Item, Remove-Item, Rename-Item and others: one noun, many verbs.

Stay in pwsh for the next step. Type exit when you want to leave.

Check it worked

You saw Hello, World! twice, a version table with Major 7 and Minor 6 (or 7), and a list of commands that all end in -Item.

Step 3 · Save and run hello.ps1

Make a folder for this tutorial and move into it. Both commands work the same on every system:

PowerShell
New-Item -ItemType Directory -Path ~/pwsh-hello-demo
Set-Location ~/pwsh-hello-demo

New-Item creates the folder and prints a line describing it. ~ means your home folder on Windows too. Set-Location is PowerShell's cd, and cd also works because it is a built-in alias for it.

In your text editor, create a file called hello.ps1 in that folder with these two lines. PowerShell scripts always end in .ps1.

PowerShell
# hello.ps1: the first PowerShell script
Write-Output "Hello, World!"

The first line starts with #, so PowerShell ignores it: it is a comment for people reading the file. The second line is the same command you typed in the shell. A script is a list of commands that PowerShell runs from top to bottom. There is no compile step you run yourself and no main function to write.

Run it from inside pwsh:

PowerShell
./hello.ps1

The ./ means "in the current folder". PowerShell does not look in the current folder for commands unless you say so, which stops a file that happens to be called ls.ps1 from hijacking a command. Forward slashes work on Windows too; you will also see .\hello.ps1 written there.

You can also run a script straight from Bash or zsh on Linux and macOS by handing it to pwsh:

Bash
cd ~/pwsh-hello-demo
pwsh ./hello.ps1

Check it worked

Both ./hello.ps1 inside pwsh and pwsh ./hello.ps1 from Bash print Hello, World!.

Step 4 · Understand the Windows execution policy

On Windows, PowerShell checks an execution policy before it runs a script file. Check yours in pwsh:

PowerShell
Get-ExecutionPolicy

What you see depends on where you are:

  • PowerShell 7 on Windows defaults to RemoteSigned. Scripts you write yourself run. Scripts downloaded from the internet must be signed by a trusted publisher, or blocked from running until you unblock them.
  • Windows PowerShell 5.1 on Windows 10 and 11 defaults to Restricted, which runs no script files at all. Running .\hello.ps1 there fails with an error that says running scripts is disabled on this system.
  • Linux and macOS print Unrestricted, and the policy cannot be changed there. Use file permissions instead.

If you need to run your own scripts in Windows PowerShell 5.1, allow local scripts for your user account only, which does not need administrator rights:

PowerShell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

If a script you downloaded and have read through is refused under RemoteSigned, remove the "downloaded from the internet" mark from that one file instead of loosening the policy:

PowerShell
Unblock-File -Path .\script-you-downloaded.ps1

Replace script-you-downloaded.ps1 with the real file name. Microsoft describes the execution policy as a safety feature, not a security boundary: it stops you running a script by accident, but it does not stop someone determined. Read a script before you unblock or run it.

Check it worked

Get-ExecutionPolicy prints RemoteSigned in PowerShell 7 on Windows, or Unrestricted on Linux and macOS, and ./hello.ps1 still runs.

Step 5 · Add a parameter with a default value

Scripts become useful when they take input. Create greet.ps1 in the same folder:

PowerShell
param(
    [string]$Name = 'World'
)

$letters = $Name.Length
Write-Output "Hello, $Name!"
Write-Output "Your name has $letters characters."

Line by line:

  • param( ... ) must be the first code in the script. It declares the inputs the script accepts.
  • [string]$Name = 'World' declares a parameter called Name. [string] says it holds text, and = 'World' is the default used when nobody passes a name.
  • $letters = $Name.Length stores a number in a new variable. $Name is a .NET string object, and .Length is one of its properties.
  • "Hello, $Name!" uses double quotes, so PowerShell replaces $Name with its value. In single quotes, 'Hello, $Name!' would print the dollar sign and the word literally.

Run it four ways:

PowerShell
./greet.ps1
./greet.ps1 -Name Amara
./greet.ps1 -Name 'Mary Jane'
./greet.ps1 Kofi

The parameter name becomes a switch you type with a dash, -Name, just like the built-in cmdlets. A value with a space needs quotes. The last call works without -Name because the first unnamed value fills the first parameter. You can also press Tab after typing ./greet.ps1 -N and PowerShell completes -Name for you, because it read the param() block.

PowerShell 7 reads and writes script files as UTF-8 by default, so names such as Adéwálé or Ọlá work in your scripts and at the prompt. Windows PowerShell 5.1 reads a script saved as UTF-8 without a byte order mark using the older Windows code page instead, and those letters come out garbled. If a script with non-English text must also run in 5.1, save it as "UTF-8 with BOM" in your editor.

Check it worked

./greet.ps1 prints Hello, World! and Your name has 5 characters., ./greet.ps1 -Name 'Mary Jane' prints Hello, Mary Jane! and Your name has 9 characters., and ./greet.ps1 Kofi prints Hello, Kofi!.

Step 6 · Pass objects through the pipeline

List the files in your folder:

PowerShell
Get-ChildItem

This prints a table with columns such as Mode, LastWriteTime, Length and Name. That table is only how PowerShell displays what it received. What Get-ChildItem actually sends is one file object per file. Pipe the objects to Select-Object and keep two properties:

PowerShell
Get-ChildItem | Select-Object Name, Length

You get something like this, where Length is the size in bytes. Your numbers can differ by a few bytes, for example if your editor saved Windows line endings:

Text
Name      Length
----      ------
greet.ps1    141
hello.ps1     70

Because Length is a real number on each object, you can filter and sort by it without cutting text into columns:

PowerShell
Get-ChildItem | Where-Object Length -gt 100
Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 1 Name, Length

Where-Object Length -gt 100 keeps only objects whose Length is greater than 100 (-gt means greater than; PowerShell uses -gt, -lt and -eq because > and < already mean redirection). Only greet.ps1 is left. The second line sorts the largest first and keeps one.

To see what kind of object you are holding and what it carries, ask it:

PowerShell
(Get-Item ./hello.ps1).GetType().FullName
Get-Item ./hello.ps1 | Get-Member -MemberType Property

The first line prints System.IO.FileInfo, the .NET type for a file. The second lists its properties, including Name, Length, Extension, CreationTime and LastWriteTime. Get-Member is the command to reach for whenever you wonder what you can do with something in a pipeline.

Check it worked

Get-ChildItem | Where-Object Length -gt 100 shows only greet.ps1, and the type check prints System.IO.FileInfo.

Step 7 · Fix the mistakes beginners make

Each of these trips up most people in their first week.

Running a script without ./. Type hello.ps1 on its own:

PowerShell
hello.ps1

PowerShell says the term is not recognised as a name of a cmdlet, function, script file or executable program, and suggests ./hello.ps1. Add the ./.

Typing powershell instead of pwsh. On Windows, powershell starts the old Windows PowerShell 5.1, with its stricter execution policy and older behaviour. Check with $PSVersionTable.PSVersion when in doubt.

Single quotes when you wanted a variable. Compare:

PowerShell
$Name = 'Ada'
'Hello, $Name'
"Hello, $Name"

The first prints Hello, $Name, the second Hello, Ada.

Expecting Windows aliases on Linux and macOS. On Windows, ls, cat and rm are aliases for Get-ChildItem, Get-Content and Remove-Item. On Linux and macOS, PowerShell leaves those names to the system's own programs, so ls prints plain text, not objects. Use the full cmdlet names in scripts that must run everywhere.

Using = or > to compare. = assigns a value and > writes to a file. To compare, use -eq, -gt and -lt: 5 -gt 3 prints True, while 5 > 3 creates a file called 3.

Check it worked

hello.ps1 without ./ shows the "not recognized" error, ./hello.ps1 works, and the two quoted lines print Hello, $Name and Hello, Ada.

Step 8 · Upgrade or remove PowerShell

To upgrade on Ubuntu, repeat the first step with a newer VERSION from the PowerShell release page. Installing the newer .deb replaces the old one. On Windows, run winget upgrade --id Microsoft.PowerShell; on macOS with Homebrew, run brew upgrade powershell.

When you are finished, the next commands delete the demo folder and everything in it, then remove PowerShell. Leave pwsh with exit first, then run them in Bash:

Bash
rm -rf ~/pwsh-hello-demo
sudo apt remove -y powershell

On Windows, run Remove-Item -Recurse ~/pwsh-hello-demo and winget uninstall --id Microsoft.PowerShell. Windows PowerShell 5.1 stays, because it is part of Windows.

Check it worked

ls ~/pwsh-hello-demo reports that there is no such file or directory, and pwsh --version reports command not found.

Next steps

  • Compare text pipelines with object pipelines: Hello World in Bash.
  • Use the same .NET platform from a compiled language: Hello World in C#.
  • See another scripting language built for text processing: Hello World in Perl.
  • Run Get-Help about_Pipelines in pwsh (after Update-Help) for Microsoft's own guide to the pipeline.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.