The SharePoint / Office 365 Developer Patterns and Practices (PnP) initiative provides a massive array of guidance, code samples and most often used by me, a PnP PowerShell command set that makes working with SharePoint (Online and on-prem) that much easier. General documentation and samples are available direct from GitHub and elsewhere , but I found I need to keep providing the same command references again and again. Therefore I provide the following list of commands and samples as a reference of what I find I use most commonly.


First of course always ensure that you have the SharePoint PnP PowerShell commands installed. You can follow the installation instructions from the SharePoint PnP PowerShell GitHub repo .

Import PnP PowerShell module if it isn’t already loaded C:\> Import-Module Microsoft.Online.Sharepoint.PowerShell Check to see if PnP PowerShell is installed, and review available PnP commands C:\> Get-Command -Module *PnP*
SharePoint / Office 365 Dev Patterns and Practices (PnP) Common PowerShell Comma ...
Get credentials (i.e. username and password) and save this in a varialbe for repeated use

Connecting to SharePoint is simple enough, but often I prefer to get and temporarily store my login credentials for reuse, i.e. during script debugging.

C:\> $credential = Get-credential
SharePoint / Office 365 Dev Patterns and Practices (PnP) Common PowerShell Comma ...
Connect to a SharePoint site using stored credentials

In the following example, I am asked to provide credentials and then using these credentials (stored in the variable, “$credential”), PowerShell will connect to my sample site in question, http://pixelmill-intranet/.

C:\> $credential = Get-credential C:\> Connect-SPOnline -url http://pixelmill-intranet/ -Credential $credential Enable a trace log for debugging

Want to debug a script? no problem, set the SPOTraceLog

C:\> Set-SPOTraceLog -On -Level Debug Export a provisioning template

One of my favorite reasons to use PnP PowerShell is for site and site asset provisioning. You can also export a provisioning template from an existing SharePoint site.

In the following example, I am exporting a provisioning template from an example SharePoint Online site. You will want to change three primary variables to enable this to work for you. You could create a PS script with parameters based on the sample below.

$tenant : Set this to your specific SharePoint Online tenant sub domain. In this example, my tenant URL is:, thus $tenant will be set the value of “MOD513885″.

$sourceSite : The path to the site to export. I am going to export from a marketing site I created, thus “/sites/marketing”.

$path : The path on your workstation where you want to save the exported provisioning template.

$credential = Get-credential # Define variables $tenant = "MOD513885"; $sourceSite = "/sites/marketing"; $path = "C:\provision-test\MyPnPTemplate.xml"; # Get context to the site in question $webUrl = "https://{0}{1}/" -f $tenant, $sourceSite; Write-Output $("Connecting to {0}..." -f $webUrl); Connect-SPOnline -Url $webUrl -Credentials $credential; Write-Output "Context obtained"; # Extract template Write-Output "Creating PnP template..."; Get-SPOProvisioningTemplate -Out $path; Write-Output $("Template saved to {0}" f $path); Apply a provisioning Template

My go to source for applying a provisioning template is straight to the PnP PowerShell GitHub documentation. Apply-SPOProvisioningTemplate Provisioning template valid handlers

Provisioning templates may have a set of handlers that may then be selectively applied to a particular site during provisioning. The best list of handlers I have found is directly in the source code for the Handler model .

An evergreen post

As I continue to find more common threads in how I work with PnP PowerShell and what questions I continue to receive, I will update this post to keep it current.

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: PowerShellGitGitHubOffice
tags: PnP,SharePoint,PowerShell,site,credential,provisioning,template,Get,gt
本文标题:SharePoint / Office 365 Dev Patterns and Practices (PnP) Common PowerShell Comma ...

技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(92)