Below you will find pages that utilize the taxonomy term “PnP PowerShell”
posts
Check if SharePoint Feature is Active Before Enabling with PnP PowerShell
When automating SharePoint site configurations with PnP PowerShell, it’s essential to check whether a feature is already active before attempting to enable it. This prevents unnecessary errors, improves script performance, and ensures idempotent operations. This guide demonstrates best practices for checking feature status and conditionally enabling features in SharePoint Online.
Table of Contents Why Check Feature Status First? Understanding SharePoint Features Prerequisites Basic Feature Check Pattern References Why Check Feature Status First?
posts
Generate Self-Signed Certificates for SharePoint Authentication with PowerShell
Certificate-based authentication is a secure method for connecting to SharePoint Online and Microsoft 365 services using service principals and automated scripts. This guide demonstrates two methods for generating self-signed certificates using PowerShell and how to use them with PnP PowerShell for SharePoint authentication.
Table of Contents Why Use Certificate-Based Authentication? Prerequisites Method 1: Using New-SelfSignedCertificate Method 2: Using New-PnPAzureCertificate Locating Your Certificate Exporting Certificates Registering Certificate with Entra ID App Connecting to SharePoint with Certificate Best Practices Troubleshooting Conclusion References Why Use Certificate-Based Authentication?
posts
Revoke Entra ID App Permissions from SharePoint Sites Using PnP PowerShell
Managing Entra ID (formerly Azure AD) app permissions across SharePoint sites is crucial for maintaining proper security governance. This guide demonstrates how to audit and revoke app permissions using PnP PowerShell, ensuring your SharePoint environment remains secure and compliant.
Table of Contents Problem Statement Understanding the Challenge Prerequisites The Solution Script Breakdown Important Considerations References Problem Statement When managing Entra ID applications with SharePoint access (especially those using Sites.Selected permissions), you may need to:
posts
Getting Started with PnP PowerShell: Modern Authentication and Multi-Tenant Setup
Introduction PnP PowerShell authentication for Microsoft 365 has evolved significantly over the years. The multi-tenant app registration approach was decommissioned for security reasons, requiring each tenant to set up its own app registration. Fortunately, the PnP team has simplified this process with automated cmdlets that streamline app registration and authentication setup.
This guide covers modern PnP PowerShell authentication methods, including interactive login setup, multi-tenant management, and certificate-based authentication.
The Evolution of PnP PowerShell Authentication Before: Multi-Tenant App Registration Single shared app registration across all tenants Simplified initial setup but created security concerns Decommissioned for enhanced security Now: Tenant-Specific App Registrations Each tenant needs to create and maintain its own app registration(s) Enhanced security and control Automated setup through PnP cmdlets Method 1: Interactive Login Setup Step 1: Create App Registration Automatically The Register-PnPEntraIDAppForInteractiveLogin cmdlet automatically creates an app registration with default permissions:
posts
PowerShell Hack: Apply Out-of-the-Box SharePoint Site Designs to Existing Sites
Introduction SharePoint site designs are powerful tools for automating site configuration, but they’re typically applied during site creation. What if you need to apply Microsoft’s out-of-the-box site designs to existing sites using automation? The PnP PowerShell, CLI for M365 and other PowerShell module cover applying custom site designs only. We can leverage a PowerShell hack using REST API calls to achieve this functionality. Thanks to Arash Aghajani who pinpointed on feasibility and requested for it to be natively available within PnP PowerShell.
posts
How to Add a SharePoint Document Library as a Tab in Microsoft Teams with PowerShell
Introduction Adding a SharePoint document library as a tab in Microsoft Teams is a common requirement for collaboration scenarios. While Teams provides an out-of-the-box (OOTB) experience for this, automating the process via PowerShell or Microsoft Graph can be tricky due to limitations.
Thanks to Tiago Duarte through the discussion within the bug he raised , he found out a solution for it using Ms Graph PowerShell and I attempted to achieve same using PnP PowerShell.
posts
PnP Powershell SharePoint: How to Use Get-PnPSearchCrawlLog
Introduction In SharePoint on premises, administrators could log directly onto servers to inspect the crawl log and monitor search indexing. In SharePoint Online, this is no longer possible, making it tricky to track crawl activity and diagnose indexing issues.
Fortunately, PnP PowerShell provides the Get-PnPSearchCrawlLog cmdlet, which allows you to inspect crawl activity programmatically.
Certain activities can significantly increase the load on SharePoint’s crawl and indexing processes, such as:
Migrating large volumes of content into the tenant Enabling OneDrive for Business Enabling or disabling Restricted Content Discoverability (RCD) to control content visibility for Copilot (see Microsoft docs) Forcing reindexing of libraries or sites, for example after changes to the search schema or to resolve search issues To avoid overloading your tenant and causing delays (such as intranet news not appearing promptly), it’s essential to plan these activities carefully—ideally performing them in phases or batches.
posts
Converting SharePoint Sharing Links to Canonical URLs with PowerShell
Introduction During a recent community discussion, Suhail Sayed presented an interesting challenge that many organizations face during SharePoint tenant migrations. The problem? Converting sharing links to their canonical URLs when documents are migrated between tenants.
The Challenge When migrating SharePoint documents from one tenant to another, organizations often encounter a specific issue with document references:
The Problem Scenario: Source tenant: Documents contain reference links to other documents Migration requirement: Update these links to reflect the new tenant Complication: Links were created using the Share option, not the Copy Link option Why This Matters: When you generate a link using SharePoint’s Share function, it creates a unique link with a randomly generated ID that redirects to the correct canonical URL.
posts
Exporting and Migrating SharePoint Libraries with Folders Using PnP PowerShell
Introduction Recently, I was asked how to export the first-level folders in document libraries using PnP PowerShell site provisioning cmdlets. While Get-PnPSiteTemplate allows exporting SharePoint site configurations, it doesn’t directly cater to folders. After experimenting with various options, including Add-PnPDataRowsToSiteTemplate, I discovered the solution: the Add-PnPListFoldersToSiteTemplate cmdlet.
The Challenge The initial attempt involved using the Add-PnPDataRowsToSiteTemplate cmdlet with a CAML query to filter folders and it did not work.
Add-PnPDataRowsToSiteTemplate -Path Site.
posts
How to Safely Rename a SharePoint Hub Site URL with PnP PowerShell
📝 Introduction
Renaming a SharePoint Hub Site URL or title is not a straightforward process. A hub site can not be renamed directly. Instead, the hub site needs to be unregistered before performing the rename, and then re-register it as a hub. This ensures the integrity of the hub structure and keeps associated sites intact.
This post provides a step-by-step PowerShell script using PnP PowerShell to automate the process, including cleanup of redirect sites and validation of associated sites.
posts
Automate SharePoint Document Set Configuration with PowerShell
Introduction Document Sets in SharePoint are a powerful way to manage groups of related documents as a single entity. They enable you to apply metadata, workflows, and permissions to a collection of documents, making them ideal for project folders, case files, or any scenario where you need to keep related content together.
This post shows how to automate the configuration of Document Sets across multiple libraries using PnP PowerShell.
Why Use Document Sets?
posts
Updating Multiline Text Field Properties in SharePoint Using PowerShell
Introduction Managing multiline text fields in SharePoint can be tricky, especially when certain field properties are not visible or editable at the library/list level, even though they are available at the site level.
For example, at the site level, you can configure properties such as:
Append Changes to Text Number of Lines Field Type: Plain Text, Rich Text, or Enhanced Rich Text However, these settings may not appear at the library/list level, as shown below:
posts
PnP PowerShell: Enabling and Configuring Document ID in SharePoint
PnP PowerShell: Enabling and Configuring Document ID in SharePoint The Document ID feature in SharePoint is a powerful tool that assigns a unique ID to files, making it easier to reference and track documents. The script within the post activates and configures the Document ID feature using PnP PowerShell. Additionally, it covers the Set-PnPSiteDocumentIdPrefix cmdlet, which simplifies the process of setting a custom prefix for Document IDs.
Why Use Document IDs?
posts
Pinning Fields to the Filter Pane in SharePoint Libraries Using PowerShell
Introduction In SharePoint Online, the filter pane is a powerful feature that allows users to quickly filter and find relevant data in libraries and lists. However, by default, not all fields are visible in the filter pane. To enhance usability, you can pin specific fields to the top of the filter pane using PowerShell or the REST API.
This blog post demonstrates how to use PowerShell and the REST API to pin fields to the filter pane in SharePoint libraries.
posts
PowerShell: Identifying SharePoint Site Creation Sources
Introduction Understanding how a SharePoint site was created is crucial for governance, compliance, and troubleshooting. In Microsoft 365, SharePoint sites can be created through various methods, such as Microsoft Teams, Viva Engage, the SharePoint Admin Center, and more. However, identifying the exact creation source can sometimes be challenging.
For example, exporting the list of active sites from the SharePoint Admin Center may not always provide accurate information. Communication sites, for instance, may incorrectly show their creation source as “Microsoft M365 Group,” even though they can only be created from the SharePoint Admin Center.
posts
Managing Microsoft 365 Group Settings with PnP PowerShell and Microsoft Graph
Introduction Managing Microsoft 365 Group settings is crucial for maintaining a compliant and secure environment.PowerShell and Microsoft Graph can be used to configure various group settings, including naming policies, guest access, and more.
As a regular user of PnP PowerShell, I aimed to replicate the functionality of the Microsoft Entra cmdlets for configuring group settings using PnP PowerShell.
Example Script to Update naming policy Settings The following PowerShell script updates the naming group settings using the Microsoft Graph API and PnP PowerShell.
posts
Azure DevOps Spfx Deployment Workload Identity Federation
Introduction Thanks to Kinga Kazala for her timely article Deploy SPFx app using pipeline’s Workload Identity federation, which showcases how to use Workload Identity Federation to alleviate the need for using Entra app secrets or certificates. This method simplifies the setup process, especially when there’s reliance on a single person who might be unavailable.
We initially set up the SPFx pipeline for the Test environment using certificates with CLI for M365.
posts
Restoring Previous Versions of Items in a SharePoint List Using PnP PowerShell
When working with SharePoint lists, there might be times when you need to restore items to a previous version. Whether it’s due to an error, unwanted changes, or simply needing to revert to an earlier state, SharePoint’s versioning feature is a lifesaver. I used the script to undo bulk changes made by a Power Automate flow after the process failed halfway due to some data needing correction. For data integrity, the bulk update needed to be undone before running the Power Automate flow again after the data corrections were made.
posts
Get Drive ID and Drive Item ID for File for Further Microsoft Graph Operations using PnP PowerShell
Introduction When working with files in SharePoint, the drive ID and drive item ID are essential parameters for further manipulation using Microsoft Graph API. The drive ID is a base64 encoded string composed of the site ID, web ID, and list ID for a particular SharePoint library. For more details, refer to Microsoft Graph: Encoding and decoding the drive ID by Mikael Svenson. The item ID part appears to be a base32 encoding of the SharePoint item’s unique ID, though the exact mechanics are still being explored.
posts
Audit Service Principal Access to SharePoint Sites with Sites.Selected Permissions
Ensuring the security and compliance of your SharePoint environment is crucial, especially when dealing with service principals, Entra ID apps, or federated identities. These entities often have elevated permissions that, if mismanaged, can lead to unauthorized access and potential data breaches. Regularly auditing these permissions is a best practice for maintaining a secure and compliant SharePoint environment.
Application only or granular access to individual site instead of whole tenant, scope called “Sites.
posts
Optimizing PowerShell Scripts to check for unique permissions in SharePoint: REST API vs. Get-PnPListItem
When working with large SharePoint sites, checking for unique permissions can be a time-consuming task. This blog post explores methods to optimize PowerShell scripts for fetching property HasUniqueRoleAssignments to determine unique permissions, including using PnP PowerShell and the SharePoint REST API. We compare their performance and highlight the advantages and limitations of each approach.
Using PnP PowerShell PnP PowerShell provides an efficient way to interact with SharePoint Online and retrieve list items to check for unique permissions.
posts
Teamifying an Existing M365 Group with PowerShell
Teamifying an Existing M365 Group with PowerShell Within M365 , SharePoint and Teams together provides a rich collaboaration platform. When a team site is created from SharePoint admin centre, it is not associated with a Teams despite a M365 group is created in the background. To extend SharePoint collaboration features , there is a need to “teamify” an existing Microsoft 365 Group, essentially attaching a new Teams instance to it to allow use of channels and other apps.
posts
Counting Files and folders within SharePoint Libraries using PnP PowerShell
Counting Files and Folders within SharePoint Libraries using PnP PowerShell This post shows a PowerShell script using PnP PowerShell module to count the number of files and folders within a SharePoint library. It might be useful doing an inventory of file count.
$SiteURL = "Counting Files within a SharePoint Library using PnP PowerShell" # Generate a unique log file name using today's date $dateTime = (Get-Date).toString("dd-MM-yyyy") $invocation = (Get-Variable MyInvocation).Value $directorypath = Split-Path $invocation.
posts
Resolving the 'PnP PowerShell Not Digitally Signed' Issue
Resolving the ‘PnP PowerShell Not Digitally Signed’ Issue If you’ve recently upgraded PnP PowerShell to the latest nightly build and are encountering errors when trying to execute any PnP PowerShell cmdlets, this guide is for you.
PS C:\Users\RAuckloo> connect-pnponline -url https://contoso-admin.sharepoint.com -Interactive connect-pnponline: The 'connect-pnponline' command was found in the module 'PnP. PowerShell', but the module could not be loaded due to the following error: [Errors occurred while loading the format data file: \\contoso-it.
posts
Retrieving File Count and Size of a folder using PnP PowerShell
Retrieving File Count and Size of a folder within a SharePoint Library using PnP PowerShell This post covers a PowerShell script that uses the PnP PowerShell module to retrieve the file count and total size of a specific folder within a SharePoint library.
#Parameters $SiteURL = "https://contoso.sharepoint.com/sites/company311" $FolderSiteRelativeURL = "Shared Documents/Test1" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Interactive #Get the folder $Folder = Get-PnPFolder -Url $FolderSiteRelativeURL -Includes ListItemAllFields #Get the total Size of the folder - with versions Write-host "Size of the Folder:" $([Math]::Round(($Folder.
posts
Retrieving SiteId from Microsoft Graph for Subsequent API Calls
Retrieving SiteId from Microsoft Graph for Subsequent API Calls This post offers an option to retrieve a SiteId from Microsoft Graph using PnP PowerShell. This can be particularly useful when making further API calls that require the SiteId.
$siteurl = "https://contoso.sharepoint.com/sites/Company311" Connect-PnPOnline -url $siteurl -interactive # for the site url https://contoso-admin.sharepoint.com/teams/app-m365 # Extract the domain and site name $uri = New-Object System.Uri($siteurl) $domain = $uri.Host $siteName = $uri.AbsolutePath # Construct the new URL $RestMethodUrl = "v1.
posts
Restrict certain SharePoint sites from tenant search and M365 Copilot using PowerShell
Excluding certain SharePoint sites from search would mean the contents from the excluded sites won’t be available to M365 tenant search and M365 Copilot using Restricted SharePoint Search feature.
The downsides using this feature are:
Limited Findability: By excluding certain SharePoint sites from search, you limit the findability of data. Users would need to know the specific sites where the data resides in order to search for it. This can hinder efficient data retrieval and records management.
posts
Managing Service Principal Permission Requests using PowerShell
Managing Service Principal Permission Requests using PowerShell Permission to the “SharePoint Online Client” service principal can be granted either in declarative method within SPFx solutions or directly. This post explores how to handle both declarative and direct permission grants using SPO PowerShell , ClI for M365 and PnP PowerShell.
PnP PowerShell Get all service principal permission grants Gets the collection of permission grants for the “SharePoint Online Client” service principal using the cmdlet Get-PnPTenantServicePrincipalPermissionGrants