PowerShell:
Using an interactive shell (REPL)

How to:

Launch PowerShell and you’re in the REPL. Try the Get-Date Cmdlet:

PS > Get-Date

You should see the current date and time output:

Wednesday, March 31, 2023 12:34:56 PM

Now, chain commands. Let’s sort processes by memory usage:

PS > Get-Process | Sort-Object WS -Descending | Select-Object -First 5

This outputs the top 5 processes by working set size (memory usage).

Deep Dive

PowerShell’s REPL has its roots in the Unix shell and other dynamic language shells like Python’s. It’s a single-user, interactive command execution environment. Unlike a compiled language where you write whole applications and then compile, a REPL environment lets you write and run code one line at a time. PowerShell also supports script execution for larger tasks.

Alternatives for Windows include the Command Prompt or other language-specific REPLs like IPython. In the Unix/Linux world, shells like bash or zsh serve a similar function.

PowerShell’s implementation uses a host application to run the shell. While PowerShell.exe in Windows is the most common, others like the Integrated Scripting Environment (ISE) or Visual Studio Code’s integrated terminal can also serve as the host.

See Also