Elemental SystemsSilicon · Boards · Software

Set Up Your Language · 7 of 14

Setting Up PowerShell

PowerShell is Microsoft's command language for automating Windows: handling files, settings, users and Microsoft's cloud services. Windows already includes an older version, Windows PowerShell 5.1, so you can start right away. We recommend also installing the newer, free PowerShell 7, which also runs on Mac and Linux.

Set-up: Easy (already on Windows)Official source: learn.microsoft.comFile ending: .ps1

New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.

1 What to download, and from where

Download only from learn.microsoft.com, Microsoft's official documentation; the install itself comes from the Microsoft Store. Other download sites can bundle unwanted software.

  1. Open the Microsoft Store (press the Windows key, type Store).
  2. Search for PowerShell and pick the one published by Microsoft Corporation.
  3. Microsoft's instructions for other ways (such as a .msi installer) are at learn.microsoft.com.

2 Install it on Windows

  1. Click Get or Install and wait for it to finish.
  2. Open Terminal. Click the small down-arrow next to the + tab button at the top: you now see PowerShell (version 7) as well as Windows PowerShell (the old one). Choose PowerShell.
  3. To make it the default, open that same menu, choose Settings, set Default profile to PowerShell and click Save.

3 Check that it worked

Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. Then type this and press Enter:

$PSVersionTable.PSVersion

What you will see: A small table. Major 7 means PowerShell 7; Major 5 means you are in the old Windows PowerShell tab.

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      5      4

If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.

4 Write and save your first program

A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)

  1. Open Notepad (press the Windows key, type Notepad, press Enter).
  2. Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
    Write-Output "Hello, World!"
  3. In Notepad choose File → Save as. Go to your C:\code folder. Set Save as type to All files (*.*), type the file name hello.ps1 exactly as shown, including the dot and the ending, and click Save.

Write-Output sends the text to the screen. PowerShell commands are usually a verb, a dash and a noun.

Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.

5 Run it and see the result

Open File Explorer, go into your C:\code folder, right-click an empty part of the window and choose Open in Terminal. (More ways to open Terminal.) If Terminal was already open from the check above and is in another folder, type cd C:\code and press Enter.

Type this and press Enter:

.\hello.ps1

What you will see: the words below on a new line. That is your program running.

Hello, World!

The .\ at the start means "in this folder". Double-clicking a .ps1 file opens it in Notepad instead of running it; that is deliberate, for safety.

Congratulations: you have written and run a PowerShell program.

6 Common beginner mistakes and how to fix them

Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.

hello.ps1 cannot be loaded because running scripts is disabled on this system

Why: Windows blocks PowerShell scripts until you allow them (the execution policy).
Fix: type this once and press Enter:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
This lets you run scripts you write yourself; scripts downloaded from the internet still need to be signed. It applies only to your own user.

The term 'hello.ps1' is not recognized ... PowerShell does not load commands from the current location by default

Why: for safety, PowerShell does not run scripts from the current folder unless you say so.
Fix: type .\hello.ps1 with the dot and backslash in front.

Nothing happens, or the script opens in Notepad when double-clicked

Why: Windows opens .ps1 files for editing, not running.
Fix: run it from Terminal as shown above, or right-click the file and choose Run with PowerShell (the window closes as soon as it finishes).