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
Kommentare