Skip to the content.

Installing Modules

Unless you’re working on a server, a PAW, with a lot of different local profiles, or with an automation solution, strongly consider always installing modules to CurrentUser scope. Its easier to maintain, update, etc

Install-Module <<MODULENAME>> -Scope CurrentUser

See Module Management in PowerShell Commands for more commands.

Terminal Emulator Quake Mode on startup

Use a shell/terminal emulator that you can start on startup and that supports what is often called quake mode. cmder and Windows Terminal support quake mode and it shouldn’t be too hard tell windows to launch them on startup.

The idea is that you will use a very quick keyboard shortcut (normally CTRL + ~) to bring up the shell and hide it (but not close it) again and often, so its quickly available for you. By reducing the time to get to the shell and also your brain becoming more aware that its quicker to get to, you will start using it more often, thus getting you more experience.

No matter what your terminal emulator to shell, learn common shortcuts to help with your speed.

Often forgotten

Checkout Commands often forgotten in PowerShell Commands
Checkout Variables often forgotten in PowerShell Commands

File Locations of PS Components

Modules

PowerShell 7:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.5

Windows PowerShell 5.1:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-5.1

Authentication Methods

-DeviceLogin: Really good if you access multiple tenants or have multiple accounts.

-Interactive

Using Single Browser with multiple profiles

Tools

https://cmder.app/: Nice terminal emulator that has a bunch of great includes. https://aka.ms/terminal / https://github.com/microsoft/terminal - i’m not totally on the Windows Terminal bandwagon yet but its not shit.

Also check Misc Tools

Traps and Gotchas

https://github.com/nightroman/PowerShellTraps

Invoke-WebRequest and Invoke-RestMethod on PS5

Invoke-WebRequest and Invoke-RestMethod on Windows PowerShell 5.1 does not have the parameter -Authentication, Only PowerShell7 does. This means you have to manually construct the header to include authentication.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-5.1
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.5#-authentication
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-5.1
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.5#-authentication

Module specific tips and Tricks

ActiveDirectory PowerShell Module

When importing ActiveDirectory module it tries to connect, and makes a new PS Drive with the creds you’re running as.

You may want to connect to a different server or a port forward to a different box via ssh, use different creds or both.

The following allows this.

# Stop AD Module auto creating a drive
$Env:ADPS_LoadDefaultDrive = 0
Import-Module ActiveDirectory
New-PSDrive -Name AD -PSProvider ActiveDirectory -Root "//RootDSE/" -Server "localhost" -Credential (Get-Credential) -Scope Global
Set-Location AD:

Scope needs to be global if running from inside scripts according to others.

Some Alternates:

https://serverfault.com/a/1095167

Sources:

Port forwarding for ActiveDirectory PowerShell

If you want to use something like SSH Port Forwarding to connect your local PowerShell instance with ActiveDirectory using different creds, Port forward localhost:9389 to domaincontroller:9389 9389 is ActiveDirectory Web Services

Specify Server if not in AD PSDrive

When using the above, you may need to either specify the server name on every ActiveDirectory CmdLet OR run all commands after you set location to the AD Drive.

Other Modules Tips and Tricks in other pages

PnP PowerShell - PS7 with import-module -UseWindowsPowerShell & caution when running inside VSCode
SharePoint Online PowerShell - PS5 best & caution when running inside VSCode
Using VSCode with PnP PowerShell
Exchange Commands

PowerShell Resources

https://github.com/janikvonrotz/awesome-powershell\