- Installing Modules
- Terminal Emulator Quake Mode on startup
- Often forgotten
- File Locations of PS Components
- Authentication Methods
- Tools
- Traps and Gotchas
- Module specific tips and Tricks
- PowerShell Resources
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:
- Modules installed in the CurrentUser scope:
- On Windows, these modules are stored in $HOME\Documents\PowerShell\Modules. The specific location of the Documents folder varies by version of Windows and when you use folder redirection. Also, Microsoft OneDrive can change the location of your Documents folder. To verify the location of your Documents folder, run use the following command: [Environment]::GetFolderPath(‘MyDocuments’).
- On non-Windows systems, these modules are stored in the $HOME/.local/share/powershell/Modules folder.
- Modules installed in the AllUsers scope:
- On Windows, these modules are stored in $env:ProgramFiles\PowerShell\Modules.
- On non-Windows systems, these modules are stored in /usr/local/share/powershell/Modules.
- Modules that ship with PowerShell are stored in $PSHOME\Modules
Windows PowerShell 5.1:
- Modules installed in the CurrentUser scope are stored in
$HOME\Documents\WindowsPowerShell\Modules. - Modules installed in the AllUsers scope are stored in
$env:ProgramFiles\WindowsPowerShell\Modules. - Modules that ship with Windows PowerShell stored in
$PSHOME\Modules, which is$env:SystemRoot\System32\WindowsPowerShell\1.0\Modules. -
$HOME\OneDrive - Contoso\Documents\WindowsPowerShell\Modules: Windows PowerShell 5.1 Modules for current user but you have OneDrive known Office folder move on. There are some hiccups and a little pain with this but its manageable.\
Authentication Methods
-DeviceLogin: Really good if you access multiple tenants or have multiple accounts.
-Interactive
Using Single Browser with multiple profiles
-
Type up tip about moving tabs when using
-devicelogin
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:
- PowerTip: Avoid Loading the AD: Drive with the Active Directory Module
- Playing with the AD: Drive for Fun and Profit
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