First Time Use of PowerShell

A PowerShell with SharePoint tutorial

PowerShell iconWhen the videos in this series were recorded, Peter Kalmström used an older version of the PnP module, called SharePointPnPPowerShellOnline, which built on PowerShell version 5. At that time, the PowerShell scripts were created in the app PowerShell ISE.

Since then, Microsoft has introduced the more powerful, cross-platform version 7 of PowerShell and the module PnP.PowerShell. It is recommended to work with this module in the source-code editor Visual Studio Code (which is not the same as Visual Studio).

Once VS Code and its PowerShell extension has been installed and registered, the code that is shown in this demo series is generally written in the same way as before.

Below are the steps to install PowerShell version 7 and VS Code, to set up Visual Studio Code for PowerShell scripting and to connect to SharePoint Online.

Note that step 9 must be performed by a Global Administrator, as permissions are set on behalf of the organization.
  1. Install PowerShell in the recommended way: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4. In Windows, it should be done via winget.
  2. Open PowerShell as an Administrator.
  3. Set the Execution policy: Set-ExecutionPolicy  -ExecutionPolicy RemoteSigned
  4. Install the module: Install-Module PnP.PowerShell
  5. Install Visual Studio Code: https://code.visualstudio.com
  6. Run VS Code as an administrator.
  7. Open the Extensions view, type PowerShell and select the PowerShell extension.
  8. Create a new .ps1 file.
  9. Register the application. Give it a name and enter your tenant name: Register-PnPEntraIDAppForInteractiveLogin  -ApplicationName "YOUR NAME"  -Tenant  TENANTNAME.onmicrosoft.com  -Interactive

    Log in and Consent to and Accept the permissions.

    Note the Client ID that you get in the VS Code Terminal. It is needed to connect to SharePoint. The ID can also be found at Entra ID >Identity >Applications >App Registrations.
  10. Import the PnP module: Import-Module PnP.PowerShell
  11. To work with a SharePoint Online site, connect to the site using Interactive mode and your Client ID: Connect-PnPOnline  -Url URL TO THE SITE -Interactive -ClientId YOUR ID
  12. Now you can develop scripts and run PowerShell 7 code in VS Code in the same way as in PowerShell ISE.
Peter shows the new way to connect in the first demo below. The process to install PowerShell and VS Code and set it up for SharePoint Online modification is also described in detail in the book PowerShell with SharePoint from Scratch.



If you prefer using the Windows PowerShell ISE, it is still available for Windows, and Microsoft have no plans to remove it. However, the ISE only works with PowerShell 5.1 and older, and even if Microsoft will continue to support ISE for security and high-priority servicing fixes, it is no longer in active feature development. Peter shows the steps forPowerShell V5 and PowerShell ISE in the demo below.



In the next article, we will show how you can avoid the login screen when you often use PowerShell with SharePoint. If you don't need that possibility now, you can go directly to the first article about app creation.

Learn more





back icon next icon
Products Buy Services Tips Books Contact About Us Tools

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved