PowerShell Cheat Sheet

PowerShell

Quick Reference

# Installed Version Check
$PSVersionTable.PSVersion

Windows Compatibility: PowerShell Core 6 compatibility with existing Windows PowerShell scripts and modules

Install-Module WindowsCompatibility -Scope CurrentUser

PowerShell Core

Multiplatform release starting with PowerShell Core 6, version 7 to be released and eventually shipped with Windows Operating Systems (including legacy 5.1 version alongside).

Requires .Net Core (Install .Net Core fromĀ here if you are a developer, you can install the SDK. Otherwise the Runtime is sufficient)

Windows Compatibility enables PowerShell Core 6 compatibility with existing Windows PowerShell scripts and modules

# Windows Compatibility

Install-Module -Name WindowsCompatibility -AllowPreRelease -Repository PSGallery   ##If running console in Windows env
Import-Module -Name WindowsCompatibility
Import-WinModule -Name <MyWindowsModule>   ##Import your required Windows Modules
Get-WinModule   ##modules available for you to import
Compare-WinModule   ##Modules that are available in Windows PowerShell but not in PS Core

SharePoint PowerShell

Modules

Blogs – Microsoft

Blogs – MVPS

Blogs – Other

Quick Reference

Links

MS Docs: PowerShell – https://docs.microsoft.com/en-us/powershellMS Doc: PowerShell Reference – https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-6
Visual Studio Code and PowerShell – https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode?view=powershell-6

SharePoint

Online: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/introduction-sharepoint-online-management-shell?view=sharepoint-psServer: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-server/sharepoint-server-cmdlets?view=sharepoint-psPNP: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps
GitHub Repo – https://github.com/SharePoint/PnP-PowerShellCommand Reference – https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

PnP PowerShell

Installs

Reference

Reference Script

Install / Update Remove

# List all Installed Modules using wildcard SharePoint

Get-Module -ListAvailable -Name *sharepoint*
Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

# INSTALL / UPDATE / REMOVE 

Install-Module SharePointPnPPowerShell2013 -SkipPublisherCheck -AllowClobber
Install-Module SharePointPnPPowerShell2016 -SkipPublisherCheck -AllowClobber
Install-Module SharePointPnPPowerShell2019 -SkipPublisherCheck -AllowClobber
Install-Module SharePointPnPPowerShellOnline -SkipPublisherCheck -AllowClobber
Update-Module SharePointPnPPowerShell*
Uninstall-Module SharePointPnPPowerShell* -AllVersions
# CONNECT / SIGN-IN

Connect-PNPOnline -Url https://tenant.sharepoint.com   ##manual connection to site

## Automatic Authentication for unattended script -setup generic password/username in credential manager (add web app url)

Connect-PnPOnline -Url https://yoursite.sharepoint.com -UseWebLogin  ##Multi-factor Auth

# USE

Get-Command -Module SharePointPnPPowerShell2016
(Get-Command -Module SharePointPnPPowerShell2016).count
Get-Command -Module SharePointPnPPowerShell2016 -verb add 

Azure PowerShell

# INSTALL

Install-Module -Name Az -AllowClobber
Install-Module -Name Az -AllowClobber -Scope CurrentUser #No Local Admin

# USE

Import-Module Az   ##Import //if autoloading diabled
Update-Module -Name Az   #Update //does not uninstall older versions
Get-InstalledModule -Name Az -AllVersions | select Name,Version  # Check installed

#CONNECT / SIGN-IN

Connect-AzAccount   ##Connect to Azure with a browser sign in token