PowerShell fundamentals
Still the main admin tool across Microsoft’s cloud: Azure, Entra, Exchange Online, Teams, SharePoint, Intune, security and compliance. This lesson is local-machine basics; connecting to the cloud services comes later.
Two PowerShells
The course runs Windows PowerShell 5.1, the one built into Windows. PowerShell 7 is the newer, separate install, and a few commands below changed or disappeared there.
| Windows PowerShell 5.1 | PowerShell 7 | |
|---|---|---|
| Launch with | powershell |
pwsh |
| Comes with Windows | Yes | No, separate install |
| Runs on | Windows only | Windows, macOS, Linux |
| ISE | Yes | No (VS Code instead) |
Getting in
- Start, search PowerShell (or right-click Start on Windows 10). Run as administrator for anything that needs admin rights, which is a lot of it.
- From Command Prompt, type
powershell. - Console for running commands; the ISE (Integrated Scripting
Environment:
iseinside PowerShell,powershell_isefrom Command Prompt or Run) for writing scripts. The ISE shows parameters and their valid values as you type. Run Script (F5) runs the whole thing, Run Selection (F8) just the highlighted lines. - The ISE is Windows PowerShell 5.1 only and gets no new features. Microsoft’s replacement is VS Code with the PowerShell extension, which has an ISE mode.
Verb-noun
Every cmdlet is Verb-Noun:
| Verb | Use |
|---|---|
| Get | Show information |
| Set | Change something |
| Remove | Delete |
| Move, Copy | Move or copy |
| Start, Stop | Start or stop (services, processes) |
Get-Verb lists all the approved verbs.
Parameters come after a dash. Some cmdlets give useful output with no parameters; others need parameters before they do anything.
Get-Service # every service and its status
Stop-Service -Name WSearch # Windows Search
Start-Service -Name WinRM
Get-Process # running processesConsole habits:
- Tab completes cmdlet and parameter names; Shift+Tab goes back.
- Up arrow recalls earlier commands.
clsclears the screen (alias forClear-Host).- No red text usually means it worked. No news is good news.
- A missing required parameter makes PowerShell prompt for it; Ctrl+C bails out.
Remoting and WinRM
WinRM (Windows Remote Management) is the service PowerShell remoting
runs over, and it has to be running on the target machine.
Enable-PSRemoting sets it up: starts WinRM and adds the firewall
rule.
Enter-PSSession -ComputerName client68 # interactive session on the remote box
Invoke-Command -ComputerName client10, client11 -ScriptBlock { Get-Service }The course also shows Get-Service -ComputerName client68 and
Get-Process -ComputerName client10, client11, client12 (a
comma-separated list hits several machines at once). Those built-in
-ComputerName parameters don’t go through WinRM; they use older
protocols. PowerShell 7 removed -ComputerName from the service
cmdlets and from Get-Process, so those examples only work in 5.1.
In 7 it’s remoting: Invoke-Command -ComputerName client10 { Get-Process }.
Piping
| sends the output of one cmdlet into the next.
Get-EventLog -LogName Security -Newest 10 | Format-List | Out-File C:\securitylog.txt
notepad C:\securitylog.txt- Default output is usually a table, and long values get cut off.
Format-Listputs each property on its own line and shows more of them than the table;Format-List *shows all of them. Out-Filewrites the output to a file.- Reading the Security log needs an admin session.
Get-EventLogis gone in PowerShell 7. The replacement works in both:Get-WinEvent -LogName Security -MaxEvents 10.
Help
Get-Help Get-EventLogshows the syntax. The first run offersUpdate-Helpto download the full help files.Get-Help Get-EventLog -Examplesfor just the examples.Get-Help Get-EventLog -Onlineopens the Microsoft Learn page. Microsoft’s own cmdlets all have one, with examples (some third-party modules don’t), and searching the cmdlet name finds it too. The course prefers those over the built-in help.
Variables
Variables start with $:
$ComputerName = "client10"
Get-Process -ComputerName $ComputerName # Windows PowerShell 5.1 only
$num = 1
$numb = 2
$num + $numb # 3Scripts and execution policy
- Scripts are
.ps1files. - Execution policy controls whether scripts run; commands typed at
the prompt always work.
Get-ExecutionPolicyshows the current one. - Defaults in Windows PowerShell 5.1: Restricted (no scripts) on
Windows 10 and 11, RemoteSigned on Windows Server. PowerShell 7 on
Windows defaults to RemoteSigned and keeps its own setting:
changing it in
powershelldoesn’t changepwsh. - RemoteSigned: local scripts run, downloaded ones need a signature. Unrestricted (what the course sets) runs anything, with a warning for downloaded scripts.
Set-ExecutionPolicy RemoteSignedchanges it for the machine (needs admin). Add-Scope CurrentUserfor just the current account, no admin needed.- It’s a safety net against running scripts by accident, not a security boundary.