Use PnP PowerShell cmdlets (SharePoint / Office 365) with PowerShell Version 7.x & Visual Studio Code

If you want to use the PnP PowerShell cmdlets for Microsoft 365 environments and products such as SharePoint Online, Microsoft Teams, Microsoft Planner, Microsoft Flow and more you need to install at least Windows PowerShell Version 7.2.

The standard PowerShell version on Windows systems is version 5.1. This version is not longer being developed and the version can only be used with Windows operating systems. The 5.1 version based on .NET Framework 4.5.

The new PowerShell generation starting with version 6.0 based on .NET Core 2.0. This means that PowerShell version 5.1 and 6.0 is completely independent. Features like the Windows PowerShell Integrated Scripting Environment (ISE) is no longer compatible with the new version 😒. For various compatibility reasons, also the following modules are no longer included in the new PowerShell:

  • Microsoft.PowerShell.LocalAccounts
  • Microsoft.PowerShell.ODataUtils
  • Microsoft.PowerShell.Operation.Validation
  • PSScheduledJob
  • PSWorkflow
  • PSWorkflowUtility
Some advantages of the new PowerShell version:
  • Based on open source and can be installed on various operating systems (Linux, MacOS, etc.)
  • Installed separately from PowerShell 5.1 (side by side)
  • Based on .NET Core runtime environment
  • Visual Studio Code is recommended for development with the new PowerShell👍

Install PowerShell 7.2 or higher

As described above to use the PnP PowerShell cmdlets for Office 365 at least PowerShell version 7.2 is required. To query the current installed version the following automatic variable can be evaluated:


Check installed or used PowerShell version

The screenshot shows the output from the variable. The left side is from a Visual Studio Code shell and the right side from the Windows ISE editor on the same machine. This means that the new PowerShell version 7.x can be installed side by side with the "classic" PowerShell 5.1 version. This means also that no upgrade is available from 5.1 to 7.x.

The installation packages for the new PowerShell version can be downloaded from the following page:

At the moment (Jan. 2024) the latest LTS version is 7.4. For the first installation the easiest option is to use the MSI package.

Visual Studio Code and PowerShell 7.x

Unlike the previous PowerShell version 5.1 there is no built-in editor available. Instead we can use Visual Studio Code to write and execute PowerShell scripts. To use PowerShell scripting experience in VS-Code we need to install the PowerShell extension for VS Code:

The Microsoft PowerShell extension for Visual Studio Code (VS Code) provides rich language support and capabilities such as syntax completions, definition tracking, and linting for PowerShell. The extension should work anywhere VS Code itself and PowerShell Core 7.2 or higher is supported. For Windows PowerShell, only version 5.1 is supported and only on a best-effort basis. PowerShell Core 6, 7.0, and 7.1 have reached end-of-support.

The extension has a lot features like:

  • New ISE compatibility mode
  • PSReadLine in the Integrated Console, including syntax highlighting, multi-line editing, and back search
  • Stability and performance improvements
  • New CodeLens integration
  • Improved path autocompletion

In Visual Studio Code it is possible to use all installed PowerShell versions on a machine. To enable support for a PowerShell version a new entry in the list of PowerShell locations is necessary. To add a new entry follow the next steps: 

  1. Open the Command Palette
  2. Use command: PowerShell: Show Session Menu
  3. Choose: Modify list of additional PowerShell locations

In the settings page a new location can be added with the button "Add Item" - see below screenshot:
Manage powershell locations in VS Code

In the screenshot there is already the entry for the new PowerShell version 7 present. To enable the ISE experience mode in VS-Code use the following steps:
  1. Open the Command Palette
  2. Use command: PowerShell: Enable ISE Mode
ISE Mode in VS Code

Now you can install the PnP PowerShell cmdlets to manage your Office 365 tenant:
Install-Module PnP.PowerShell -Scope CurrentUser

For a list of all possible installation options see the official PnP PowerShell page:


Beliebte Posts aus diesem Blog

Exchange Online: Schutzregel für E-Mail Weiterleitung

Vertikaler Bereich deaktiviert

Power Automate: Abrufen von SharePoint Listenelementen mit ODATA-Filter