PowerShell 7 - Essentials

Hello koalas,

This article is about the essentials things to know about PowerShell 7. I hope you'll enjoy reading it.

Table of Contents

History of PowerShell

Before to be named as PowerShell, it was called "Monad".

PowerShell has been built at the top of .NET Framework.

PowerShell is an object-oriented/centered language. It works with objects and pipeline.

The scripting language is interactive. You can use the autocompletion system to help you writing faster and more efficiently your code.

YearVersioningOS integrated
2006PowerShell 1.0Windows XP SP2, Windows Server 2003 SP1, Windows Vista
2009PowerShell 2.0Windows 7, Windows Server 2008 R2, Windows XP SP3, Windows 2003 SP2, Windows Vista SP1
2012PowerShell 3.0Windows 8, Windows Server 2012, Windows 7 SP1, Windows Server 2008 SP1, Windows Server 2008 R2 SP1
2013PowerShell 4.0Windows 8.1, Windows Server 2012 R2, Windows 7 SP1, Windows Server 2008 R2 SP1, Windows Server 2012
2016PowerShell 5.0 / 5.1Windows 10 Build 1607, Windows Server 2016, Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2
2018-2019PowerShell Core 6 / 6.1 / 6.2Windows 10, Windows Server 2019, Linux, MacOS
2020PowerShell 7Windows 10, Windows Server 2019, Linux, MacOS

Why PowerShell is important to know?

  • PowerShell can manage anything from anywhere and is multiplatform (Windows, Linux, Mac)
  • PowerShell can manage local systems and services
  • PowerShell can connect to the cloud (ex: Microsoft Azure, Amazon AWS)
  • PowerShell is a powerful automation language
  • PowerShell is consistency
  • PowerShell provides documentation (ex: Get-Help)
  • PowerShell can import modules (extensions)

What are the differences between PowerShell 5.1 and PowerShell 7?

PowerShell 5.1PowerShell 7
ProprietaryOpen Source
Windows platforms onlyWindows, Linux, MacOS
Ships with WindowsManual install
PowerShell 5.1 is feature complete (no more development)Active development (the one to use)
PowerShell ISEVisual Studio Code
powershell.exepwsh.exe

As you can see above, PowerShell 7 is the one to learn and go ahead with.

PowerShell 7 has the big advantage to be able to work on Linux and MacOS as well.

PowerShell 7 also can load modules (commands) from PowerShell 5.1 if some commands are missing with the latest version.

Important: PowerShell Core 7 can be installed along Microsoft PowerShell 5.1. Both versions can work at the same time on the same machine.

Terminology

CmdletA cmdlet (pronounce command-let) is kind of "tiny" command.
A cmdlet is a compiled code.
A cmdlet does one thing (same as a Linux command).
Function

A function behaves just like a cmdlet.
Often written in PowerShell script.
It does one thing.

ScriptA script is a PowerShell "batch" file with a .ps1 extension.
A script runs cmdlets and functions in a structured format.
A script can be used to automate task sequences.
AliasAn alias is an alternate name for a cmdlet, function, or script.
It simplifies typing (usually shorter).
An alias allows users to make the transition from bash (cmd), Linux, or even MacOS. It's an aid for new comers.
ParameterA parameter is used by all command types.
A parameter customizes the behavior of the command.
A parameter could be "positional". It means it has to be in a specific position to be accepted by the command.
A parameter syntax is always: -ParameterName Value(,Value2, Value3,...).

Naming convention

PowerShell has a naming convention: Verb-Noun (always a dash (-) between verb and noun)

The verbs are from the .NET Standard. You can see the full list with the command:

Get-Verb

The nouns are singular version of the word you use. It also can be prefixed to facilitate the understanding.

Get-WinEvent
Get-WindowsUpdate

Basic commands

Check PowerShell Version ($PSVersionTable)

Command$PSVersionTable
DescriptionShows information about the version of PowerShell.
Example$PSVersionTable
Output

Launch a PowerShell 5.1 session

Commandpowershell.exe
Description
Launches a new Powershell 5.1 session.
Example

powershell.exe
$PSVersionTable

Output

Launch a PowerShell 7 session

Commandpwsh
DescriptionLaunches a new PowerShell 7 session.
Examplepwsh
$PSVersionTable
Output

Open the official PowerShell documentation website from Microsoft

Commandstart https://aka.ms/powershell
Description
Goes to the official PowerShell documentation from Microsoft.
Example
start https://aka.ms/powershell
Output

Get current credentials (whoami)

Commandwhoami
DescriptionCheck the current credentials used.
Examplewhoami
OutputYourComputerName\username

Write text to a file (echo >)

Commandecho "Your text" > filePath
DescriptionWrite text to a file.
Exampleecho "First line" > MyTextFile.txt
Output

Append text to a file (echo >>)

Commandecho "Your text" >> filePath
DescriptionAppend text to a file.
Exampleecho "Second line" >> MyTextFile.txt
Output

Clear the screen of the shell, the terminal (cls)

Commandcls or Clear-Host
DescriptionClear the screen (of your shell/terminal).
Examplecls
Clear-Host
Output

Create a directory, a folder (mkdir)

Commandmkdir, md, or New-Item -ItemType Directory
DescriptionCreate a directory, a folder.
Examplemkdir "YourFolderName1"
md "YourFolderName2"
New-Item -ItemType Directory -Name "YourFolderName3"
Output

Delete, remove a directory, a folder (rmdir)

Commanddel, Remote-Item -Path "YourFolderName"
DescriptionDelete a directory, a folder.
Exampledel "YourFolderName1"
Remove-Item -Path "YourFolderName2"
rmdir "YourFolderName3"
OutputNothing to show because it has been deleted.

Run an application from the shell, terminal

Commandnotepad, calc, pwsh, powershell, and so on
DescriptionRun an application from the shell, the terminal.
Examplenotepad
calc
pwsh
powershell
...
OutputThe application you've run.

Calculate with PowerShell

CommandA calculation
DescriptionCalculate what you have typed.
Example2*2
(3*4)-2
Output4
10

Get-Command

CommandGet-Command
DescriptionGet all commands on your system.
ExampleGet-command -Verb Get -Noun win*
Output

Get-Command -CommandType

CommandGet-Command -CommandType <type>
DescriptionGet the type of a command.
ExampleGet-Command -CommandType Cmdlet
Get-Command -CommandType Function
Get-Command -CommandType Script
Get-Command -CommandType Alias
Get-Command -CommandType Application
OutputList of commands with the <type> you choose.

List processes (ps, Get-Process)

Commandps or Get-Process
DescriptionList processes on your computer.
Exampleps *explorer*
Get-Process *explorer*
Output

Show-Command

CommandShow-Command
DescriptionShow a Window with all the commands present on your system. You also can use fields to create your command and then use the "Run" or "Copy" button at the bottom of the Window.
ExampleShow-Command
Output

That's it for this article! I hope you enjoyed reading it.

Keep learning,
Didier