Get started with the PnP PowerShell cmdlets for Office 365 (SharePoint & Co.)

A lot of features and functions within Office 365 can only be managed with PowerShell. Of course everything can be controlled with the standard PowerShell module Microsoft.Online.Sharepoint.PowerShell but only with this module some tasks are very complex to realize. For example to change the standard search scope in SharePoint Online without the PnP extension you need the following code:

With the PnP extension only one line of script code is necessary:

$siteURL = "https://my-sharepoint-domain.sharepoint.com/sites/Sales"
$userAccess = Get-Credential 
Try {
    $currentCtx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
    $currentCtx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userAccess.UserName,$userAccess.Password)
    $web = $currentCtx.Web
    $currentCtx.Load($web)
    $currentCtx.ExecuteQuery()
 
    $web.SearchScope = 1
    $web.Update()
    $currentCtx.ExecuteQuery()
}
Catch {
    // log or show error
}

With the PnP PowerShell extensions for Office 365 the setting can be set very easy with one line of code plus one line for authentification:

Connect-PnPOnline -Url "https://my-sharepoint-domain.sharepoint.com/sites/Sales" -Interactive
Set-PnPSearchSettings -SearchScope Tenant # DefaultScope | Hub | Site | Tenant

I think this is a good example to demonstrate the advantages of the PnP PowerShell cmdlets extensions.

Installation PnP PowerShell cmdlets

The installation process is very easy. The module can be installed via:

Install-Module PnP.PowerShell -Scope CurrentUser

To use the commands it is necessary to register an Entra ID Application. To do so use the following command:
Register-PnPManagementShellAccess
The user needs at least write access to the Entra ID. After the app registration the PnP commands can be used. The app itself act as delegate this means to execute commands the script user must be authenticated with his/her credentials. You can find all details here:

Kommentare

Beliebte Posts aus diesem Blog

Exchange Online: Schutzregel für E-Mail Weiterleitung

Vertikaler Bereich deaktiviert

EntityFrameworkCore.DbUpdateException: Could not save changes because the target table has database triggers. Please configure your entity type accordingly