Installing PnP PowerShell for SharePoint Online

Loading

PnP PowerShell (Patterns & Practices PowerShell) is a cross-platform command-line tool designed to automate and manage SharePoint Online, Microsoft 365, and Teams environments. It simplifies administrative tasks such as site management, list handling, user permissions, and document operations.


Step 1: Prerequisites

Before installing PnP PowerShell, ensure you have:
Windows 10/11, macOS, or Linux
PowerShell 7+ (for cross-platform support)
Administrator privileges (for system-wide installation)
Access to SharePoint Online (Microsoft 365)


Step 2: Installing PnP PowerShell

1. Open PowerShell

  • On Windows: Press Win + X, then select PowerShell (Admin) or Terminal.
  • On macOS/Linux: Open Terminal and ensure PowerShell 7+ is installed.

2. Install PnP PowerShell

Run the following command:

Install-Module -Name PnP.PowerShell -Scope CurrentUser
  • The -Scope CurrentUser flag installs PnP PowerShell only for the current user.
  • To install it for all users (requires admin rights), use: Install-Module -Name PnP.PowerShell -Scope AllUsers

3. Update PnP PowerShell (Optional but Recommended)

Ensure you have the latest version with:

Update-Module -Name PnP.PowerShell

4. Verify Installation

Check if PnP PowerShell is installed by running:

Get-Module -Name PnP.PowerShell -ListAvailable

Step 3: Connecting to SharePoint Online

1. Connect Using Interactive Login

Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Interactive

This opens a browser window where you can sign in using your Microsoft 365 credentials.

🔹 2. Connect Using Credentials (Not Recommended for Security Reasons)

$cred = Get-Credential
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Credentials $cred

3. Connect Using Azure AD App (For Automation)

If using an app registration with certificate authentication, run:

Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -ClientId "<App_ID>" -Tenant "<Tenant_ID>" -CertificatePath "<Path_To_Cert>"

4. Disconnect from SharePoint

To end the session, run:

Disconnect-PnPOnline

Step 4: Common Issues & Troubleshooting

Issue: Installation fails due to missing PowerShell version
✔ Solution: Upgrade to PowerShell 7+ using:

winget install --id Microsoft.Powershell --source winget

Issue: “Untrusted repository” warning during installation
✔ Solution: If prompted, type Y to confirm installation.

Issue: Module not found after installation
✔ Solution: Try restarting PowerShell or running:

Import-Module PnP.PowerShell

Step 5: Uninstalling PnP PowerShell

If you no longer need PnP PowerShell, remove it using:

Uninstall-Module -Name PnP.PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *