SlideShare a Scribd company logo
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Introduction to
SharePoint Patterns and Practices
(PnP) PowerShell
Theresa Eller
@SharePointMadam | sharepointmadam@gmail.com
sharepointmadam.blogspot.com | slideshare.net/sharepointmadam
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Theresa Eller
1
SharePoint Saturday
sharepointmadam.blogspot.com
Video featured on Webucator’s
YouTube channel
aOS.community
(Azure, Office 365 & SharePoint Community)
@SharePointMadam
#sphelp
Community Involvement
Shay & Cookie
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Agenda
Installing SharePoint PnP
SharePoint PnP
Script - Save Site As Template
Working Through Script Errors
Resources
2
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
3
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
SharePoint Patterns and Practices
Originally formed in 2013 by a group of Microsoft
consultants who were working on the transformation
effort of the Office 365 Dedicated customers to Multi-
Tenant
SharePoint / Office 365 Dev PnP is not directly linked
with the official Patterns and Practices team at Microsoft
Done by the community for the community
4
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
PnP PowerShell Overview
“SharePoint Patterns and Practices (PnP) contains a
library of PowerShell commands (PnP PowerShell) that
allows you to perform complex provisioning and artifact
management actions towards SharePoint. The
commands use CSOM and can work against both
SharePoint Online as SharePoint On-Premises.”
5
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
PowerShellGet
PowerShell module with commands for discovering,
installing, updating and publishing the PowerShell
artifacts like Modules, DSC Resources, Role Capabilities
and Scripts
Is integrated with the PackageManagement module (in
Windows 10) as a provider so that users can also use the
PackageManagement cmdlets for discovering, installing
and updating the PowerShell artifacts like Modules and
Scripts
6
https://github.com/powershell/powershellget
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
PowerShellGet Requirements for Windows 7
Windows PowerShell 3.0 or newer
PackageManagement module
• a.k.a. Windows Management Framework 4.0 (or higher)
PowerShellGet module
7
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
PowerShellGet Installation Steps (1 of 2)
Save the PowerShellGet module to a local directory
• Source: https://github.com/PowerShell/PowerShellGet/releases
Run PowerShell/SPO Management Console with
elevated permissions
Method 1
• Navigate to the local directory
• Import the module
o Import-Module path/to/PowerShellGet/PowerShellGet
8
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
PowerShellGet Installation Steps (2 of 2)
Method 2
• Save-Module PowerShellGet –Path C:LocalFolder
• Delete contents of
$env:ProgramFilesWindowsPowerShellModulesPowerShellGet
 and
$env:ProgramFilesWindowsPowerShellModulesPackageMana
gement folders
• Re-open the PS Console with elevated permissions
• Copy-Item "C:LocalFolderPowerShellGet*"
"$env:ProgramFilesWindowsPowerShellModulesPowerShellGe
t" -Recurse –Force
• Copy-Item "C:LocalFolderPackageManagement*"
"$env:ProgramFilesWindowsPowerShellModulesPackageMana
gement" -Recurse -Force
9
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Installing SharePointPnPPowerShell (1 of 2)
For Windows 7, import PowerShellGet module
then
Windows 7 or 10
• Download the SharePointPnPPowerShell* module to
C:WindowsSystem32WindowsPowerShellv1.0
o June 2017 release
https://github.com/sharepoint/pnp/powershell/releases/tag/2.16.1706.0
• Run PowerShell (or SPO Management Console) as administrator
• Install SharePointPnPPowerShell* module (next slide)
o SharePointPnPPowerShellOnline requires SharePoint Online
Management Shell
10
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Installing SharePointPnPPowerShell (2 of 2)
Import the SharePointPnPSharePoint* module
• Install-Module SharePointPnPPowerShellOnline
• Install-Module SharePointPnPPowerShell2016
• Install-Module SharePointPnPPowerShell2013
11
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Import, Install, Connect
12
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
13
Save Site As Template
A real world experience
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Save Site As Template – Team Site
14
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Save Site As Template – Publishing Site
SharePoint Designer
15
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
16
Script
Variables | Extract | Create | Apply
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Script Variables
$credential = Get-credential
#Define variables
$tenant = "<tentant>";
$sourceSite = "/<relative URL>"; [site template to save]
$targetSite = "/<relative URL>"; [where to build new site]
$subSite = "/<relative URL>"; [new site to build]
$path = "C:PnP<templatename>.xml";
[where to store template]
$siteTitle = "<sitetitle>";
$siteDescription = "<sitedescription>";
$siteUrl = "/<subsite>"; [relative URL of new site]
17
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Get Context (Source Site)
$webUrl = "https://{0}.sharepoint.com{1}/" -f $tenant,
$sourceSite;
Write-Output $("Connecting to {0}..." -f $webUrl);
Connect-PnPOnline -Url $webUrl -Credentials
$credential;
Write-Output "Context obtained";
18
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Connect-PnPOnline
Connects to a SharePoint site and creates a context that
is required for the other PnP Cmdlets
Get-Help Connect-PnPOnline –Examples
Get-Help Connect-PnPOnline –Detailed
19
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Get/Set-PnPContext
Sets the context to use by the cmdlets
• Useful for switching between sites
Connect-PnPOnline –Url $siteAurl –Credentials $Credentials
$ctx = Get-PnPContext
Get-PnPList
Connect-PnPOnline –Url $siteBurl –Credentials $Credentials
Get-PnPList
Set-PnPContext
Get-PnPList
20
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Extract Template
Write-Output "Creating PnP template...";
#Include necessary parameters
Get-PnPProvisioningTemplate -PersistBrandingFiles
-PersistPublishingFiles -IncludeSiteGroups -Out $path;
Write-Output $("Template saved to {0}" -f $path);
21
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Parameters
Get-PnpProvisioningTemplate parameters included in
script
22
Parameter Type Required Description
IncludeSiteGroups SwitchParameter False
If specified all site groups will
be included.
PersistBrandingFiles SwitchParameter False
If specified the files used for
masterpages, sitelogo,
alternate CSS and the files
that make up the composed
look will be saved.
PersistPublishingFiles SwitchParameter False
If specified the files used for
the publishing feature will be
saved.
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Get Context (Target Site)
$webUrl = "https://{0}.sharepoint.com{1}/" -f $tenant,
$targetSite;
Write-Output $("Connecting to {0}..." -f $webUrl);
Connect-PnPOnline -Url $webUrl -Credentials
$credential;
Write-Output "Done";
23
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Create New Sub-site
#Change the Locale ID if necessary
#Change the Site Template if necessary
$web = New-PnPWeb -Title "<sitetitle>" -Url $subSite
-Description "<sitedescription>" -Locale 1033 -Template
"<Site Template>";
or
$web = New-PnPWeb -Title $siteTitle -Url $subSite
-Description $siteDescription -Locale 1033 -Template
"<Site Template>";
24
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Get Context (Sub-site)
$webUrl = "https://{0}.sharepoint.com{1}/" -f $tenant,
$subSite;
Write-Output $("Connecting to {0}..." -f $webUrl);
Connect-PnPOnline -Url $webUrl -Credentials
$credential;
Write-Output "Done";
25
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Turn On TraceLog
Set-PnPTraceLog -on -level debug
26
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Apply Template
Write-Output $("Applying PnP template [{0}] to site [{1}
({2})]..." -f $path, $web.Title, $web.Url);
Apply-PnPProvisioningTemplate -Path $path;
Write-Output "Done";
27
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Disconnect
Disconnect-PnPOnline
28
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
29
Working Through Script Errors
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Site Collection Features
Issue:
• Site collections features that are activated on the source site
collection but not the target site collection can cause applying the
template to fail, with error “Feature with Id <featureID>' is not
installed in this farm, and cannot be added to this scope.”
Example:
• Feature with Id '863b4392-e4a4-460e-ae8d-14c29b14f14a' is not
installed in this farm, and cannot be added to this scope.
Solution:
• Compare the site collection features from the source site
collection to the target site collection
• On the target site collection, activate any site collection features
that are activated on the source site collection
30
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Site Features
Issue:
• Site features that are activated on the source site but not the
target site can cause applying the template to fail, with an error of
feature missing
Solution:
• Compare the site features from the source site to the target site
• On the target site, activate any site features that are activated on
the source site
• In the template XML file, delete the feature that “is not installed in
this farm, and cannot be added to this scope”
31
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Error Updating Field
Updating field 413213c2-3e91-4dc8-9d47-216b83ab8027
failed: The field was found invalid: {{listid:Deliverables}
• Search the Internet for “SharePoint [field ID]”
• Go to the list settings and click on the field to open it
or
• Delete the column or list
o Re-create it manually or let the script re-create it
32
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Content Types (1/2)
Error:
• Referenced content type
0x01010029AB996A778A324EAEF918C866ECBD19 not
available in site or in template
Solution:
• Copy the Content Type ID from the PowerShell window and
search for it in the template
• Delete document-specific content type IDs from the template XML
file
o Happens because content is not copied
from original site to new site
33
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Content Types (2/2)
Resources:
• Content Type IDs
https://msdn.microsoft.com/en-
us/library/office/aa543822(v=office.14).aspx
• Base Content Type Hierarchy
https://msdn.microsoft.com/en-
us/library/office/ms452896(v=office.14).aspx
34
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Source Site Target Site
Default Content Type Not Updated
35
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Can’t Customize Permission Levels (1/2)
Apply-PnPProvisioningTemplate : You cannot customize
permission levels in a web site with inherited permission
levels.
36
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Can’t Customize Permission Levels (2/2)
37
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
All Sitegroups
WARNING: You are requesting to export sitegroups from
a subweb. Notice that ALL sitegroups from the site
collection are included in the result.
38
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Connection Closed by the Server
Get-PnPProvisioningTemplate : The underlying
connection was closed: A connection that was expected
to be kept alive was closed by the server.
39
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Error with Argument (1/2)
The argument must be a single file name and cannot
contain path characters
40
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Error with Argument (2/2)
Trying to create a master page library at the subsite level
• Master pages are stored at the site collection level
• Unnecessary for a subsite
41
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Specified Argument Out of Range
Apply-PnPProvisioningTemplate : Specified argument
was out of the range of valid values.
• Not the Cause: OOTB web part (Newsfeed) was removed from
homepage
42
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Custom Web Parts
Purchased/downloaded from SharePoint Store
Delete code from XML file
43
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Copy File
Copy-PnPFile -SourceUrl
<relativeURL/filename.extension>
-TargetUrl <relative URL>
• Copy site logos and other pictures or files that are needed on
each site
44
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
45
Resources
NJSPUG-Introduction to SharePoint Patterns and Practices PowerShell
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Resources
https://dev.office.com/patterns-and-practices
How to get started with Office Dev PnP web cast
SharePoint PnP Webcast – What should SharePoint
Administrators know about SharePoint Framework?
https://github.com/SharePoint/PnP
PnP PowerShell – GitHub repository
SharePoint Online Management Shell
Windows Management Framework
Cmdlet Documentation
47
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Special Thanks To…
Antii K. Koskela (@koskila)
Eric Skaggs (@skaggsej)
Eric Overfield (@ericoverfield)
Erwin van Hunen (@erwinvanhunen)
Nick van Denheuvel
@officedevpnp
48
Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited.
Questions?
Theresa Eller
@SharePointMadam | sharepointmadam@gmail.com
sharepointmadam.blogspot.com | slideshare.net/sharepointmadam

More Related Content

PDF
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
PPTX
PowerShell: Through the SharePoint Looking Glass
PPTX
How to do everything with PowerShell
PDF
PowerShell Introduction to Administering SharePoint On-Premises & O365
PPTX
Getting started with Office365/SharePoint Patterns and Practices
PPTX
Managing SharePoint Anywhere with Windows PowerShell
PPTX
PowerShell Basics for Office Apps and Servers
PPTX
SPSTC - PowerShell - Through the SharePoint Looking Glass
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
PowerShell: Through the SharePoint Looking Glass
How to do everything with PowerShell
PowerShell Introduction to Administering SharePoint On-Premises & O365
Getting started with Office365/SharePoint Patterns and Practices
Managing SharePoint Anywhere with Windows PowerShell
PowerShell Basics for Office Apps and Servers
SPSTC - PowerShell - Through the SharePoint Looking Glass

Similar to NJSPUG-Introduction to SharePoint Patterns and Practices PowerShell (20)

PPTX
Intro to PowerShell
PPTX
SPSSTL - PowerShell - Through the SharePoint Looking Glass
PPTX
Power Shell and Sharepoint 2013
PPTX
All You Need to Know for Automated SharePoint Site Provisioning with PnP Powe...
PPTX
Using PowerShell for SharePoint 2013
PDF
Operacion Guinda 2
PDF
I6 - State of the art SharePoint PowerShell Nation 2017 - Spencer Harbar
PPTX
SPugPt Meeting 35: Manage govern and drive adoption of share point online wit...
PDF
SPSSA - Site Collection Admin
PPTX
Who Needs A Developer For Automated SharePoint Provisioning
PDF
SPSLA - You are the Site Collection Admin
PPTX
Admin SharePoint 2010 with PowerShell
PPTX
SPS NYC Using the Office Dev PnP to Accelerate Your Productivity
PPTX
Make the hosting company life easier with SharePoint PowerShell
PDF
Introduction to PowerShell
PPTX
Making Life Easier with PowerShell (SPSVB 2012)
PPTX
Power shell for sp admins
PPTX
Making Life Easier with PowerShell - SPSRIC
PPTX
Intro to SharePoint + PowerShell
PDF
2018-10-17 J1 5D - Use the PnP SharePoint starter kit to create your Intranet...
Intro to PowerShell
SPSSTL - PowerShell - Through the SharePoint Looking Glass
Power Shell and Sharepoint 2013
All You Need to Know for Automated SharePoint Site Provisioning with PnP Powe...
Using PowerShell for SharePoint 2013
Operacion Guinda 2
I6 - State of the art SharePoint PowerShell Nation 2017 - Spencer Harbar
SPugPt Meeting 35: Manage govern and drive adoption of share point online wit...
SPSSA - Site Collection Admin
Who Needs A Developer For Automated SharePoint Provisioning
SPSLA - You are the Site Collection Admin
Admin SharePoint 2010 with PowerShell
SPS NYC Using the Office Dev PnP to Accelerate Your Productivity
Make the hosting company life easier with SharePoint PowerShell
Introduction to PowerShell
Making Life Easier with PowerShell (SPSVB 2012)
Power shell for sp admins
Making Life Easier with PowerShell - SPSRIC
Intro to SharePoint + PowerShell
2018-10-17 J1 5D - Use the PnP SharePoint starter kit to create your Intranet...
Ad

More from Theresa Lubelski (20)

PDF
Modern_Site_Owner_M365_Ottawa.pdf
PPTX
Inside The Vault: Bridging the Social Distancing Gap with SharePoint and Teams
PDF
SPS Warsaw - Achieving a Consistent User Experience
PPTX
SPS Cincinnati Modern SharePoint Experience
PPTX
SPSCLT - The Latest Modern SharePoint Features
PPTX
SPS Nashville Modern Sharepoint Experience
PPTX
SPS Nashville Modern Sharepoint Experience
PDF
NACS Mix It Up With Modern SharePoint Sites
PDF
Mix It Up with Modern SharePoint Sites
PDF
SPSSAC - SharePoint 101
PDF
SPSSAC - Taking Content Management Beyond Content Types
PDF
SPSHOU SharePoint 2013 Best Practices
PDF
SPSSA SharePoint 101 Best Practices
PDF
SPSSA SharePoint 101 Best Practices - 3 Slides PP
PPTX
Branson - Taking Content Management Beyond Content Types
PPTX
Branson - Self-Service Business Intelligence for On-Prem Organizations
PPTX
HTF-Taking Content Management Beyond Content Types
PPTX
Taking Content Management Beyond Content Types - SPS Paris
PPTX
Self-Service Business Intelligence with Power BI
PDF
SPSDFW-Taking Content Management Beyond Content Types
Modern_Site_Owner_M365_Ottawa.pdf
Inside The Vault: Bridging the Social Distancing Gap with SharePoint and Teams
SPS Warsaw - Achieving a Consistent User Experience
SPS Cincinnati Modern SharePoint Experience
SPSCLT - The Latest Modern SharePoint Features
SPS Nashville Modern Sharepoint Experience
SPS Nashville Modern Sharepoint Experience
NACS Mix It Up With Modern SharePoint Sites
Mix It Up with Modern SharePoint Sites
SPSSAC - SharePoint 101
SPSSAC - Taking Content Management Beyond Content Types
SPSHOU SharePoint 2013 Best Practices
SPSSA SharePoint 101 Best Practices
SPSSA SharePoint 101 Best Practices - 3 Slides PP
Branson - Taking Content Management Beyond Content Types
Branson - Self-Service Business Intelligence for On-Prem Organizations
HTF-Taking Content Management Beyond Content Types
Taking Content Management Beyond Content Types - SPS Paris
Self-Service Business Intelligence with Power BI
SPSDFW-Taking Content Management Beyond Content Types
Ad

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MIND Revenue Release Quarter 2 2025 Press Release
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25 Week I
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools

NJSPUG-Introduction to SharePoint Patterns and Practices PowerShell

  • 1. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Introduction to SharePoint Patterns and Practices (PnP) PowerShell Theresa Eller @SharePointMadam | sharepointmadam@gmail.com sharepointmadam.blogspot.com | slideshare.net/sharepointmadam
  • 2. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Theresa Eller 1 SharePoint Saturday sharepointmadam.blogspot.com Video featured on Webucator’s YouTube channel aOS.community (Azure, Office 365 & SharePoint Community) @SharePointMadam #sphelp Community Involvement Shay & Cookie
  • 3. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Agenda Installing SharePoint PnP SharePoint PnP Script - Save Site As Template Working Through Script Errors Resources 2
  • 4. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. 3
  • 5. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. SharePoint Patterns and Practices Originally formed in 2013 by a group of Microsoft consultants who were working on the transformation effort of the Office 365 Dedicated customers to Multi- Tenant SharePoint / Office 365 Dev PnP is not directly linked with the official Patterns and Practices team at Microsoft Done by the community for the community 4
  • 6. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. PnP PowerShell Overview “SharePoint Patterns and Practices (PnP) contains a library of PowerShell commands (PnP PowerShell) that allows you to perform complex provisioning and artifact management actions towards SharePoint. The commands use CSOM and can work against both SharePoint Online as SharePoint On-Premises.” 5
  • 7. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. PowerShellGet PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, DSC Resources, Role Capabilities and Scripts Is integrated with the PackageManagement module (in Windows 10) as a provider so that users can also use the PackageManagement cmdlets for discovering, installing and updating the PowerShell artifacts like Modules and Scripts 6 https://github.com/powershell/powershellget
  • 8. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. PowerShellGet Requirements for Windows 7 Windows PowerShell 3.0 or newer PackageManagement module • a.k.a. Windows Management Framework 4.0 (or higher) PowerShellGet module 7
  • 9. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. PowerShellGet Installation Steps (1 of 2) Save the PowerShellGet module to a local directory • Source: https://github.com/PowerShell/PowerShellGet/releases Run PowerShell/SPO Management Console with elevated permissions Method 1 • Navigate to the local directory • Import the module o Import-Module path/to/PowerShellGet/PowerShellGet 8
  • 10. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. PowerShellGet Installation Steps (2 of 2) Method 2 • Save-Module PowerShellGet –Path C:LocalFolder • Delete contents of $env:ProgramFilesWindowsPowerShellModulesPowerShellGet and $env:ProgramFilesWindowsPowerShellModulesPackageMana gement folders • Re-open the PS Console with elevated permissions • Copy-Item "C:LocalFolderPowerShellGet*" "$env:ProgramFilesWindowsPowerShellModulesPowerShellGe t" -Recurse –Force • Copy-Item "C:LocalFolderPackageManagement*" "$env:ProgramFilesWindowsPowerShellModulesPackageMana gement" -Recurse -Force 9
  • 11. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Installing SharePointPnPPowerShell (1 of 2) For Windows 7, import PowerShellGet module then Windows 7 or 10 • Download the SharePointPnPPowerShell* module to C:WindowsSystem32WindowsPowerShellv1.0 o June 2017 release https://github.com/sharepoint/pnp/powershell/releases/tag/2.16.1706.0 • Run PowerShell (or SPO Management Console) as administrator • Install SharePointPnPPowerShell* module (next slide) o SharePointPnPPowerShellOnline requires SharePoint Online Management Shell 10
  • 12. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Installing SharePointPnPPowerShell (2 of 2) Import the SharePointPnPSharePoint* module • Install-Module SharePointPnPPowerShellOnline • Install-Module SharePointPnPPowerShell2016 • Install-Module SharePointPnPPowerShell2013 11
  • 13. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Import, Install, Connect 12
  • 14. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. 13 Save Site As Template A real world experience
  • 15. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Save Site As Template – Team Site 14
  • 16. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Save Site As Template – Publishing Site SharePoint Designer 15
  • 17. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. 16 Script Variables | Extract | Create | Apply
  • 18. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Script Variables $credential = Get-credential #Define variables $tenant = "<tentant>"; $sourceSite = "/<relative URL>"; [site template to save] $targetSite = "/<relative URL>"; [where to build new site] $subSite = "/<relative URL>"; [new site to build] $path = "C:PnP<templatename>.xml"; [where to store template] $siteTitle = "<sitetitle>"; $siteDescription = "<sitedescription>"; $siteUrl = "/<subsite>"; [relative URL of new site] 17
  • 19. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Get Context (Source Site) $webUrl = "https://{0}.sharepoint.com{1}/" -f $tenant, $sourceSite; Write-Output $("Connecting to {0}..." -f $webUrl); Connect-PnPOnline -Url $webUrl -Credentials $credential; Write-Output "Context obtained"; 18
  • 20. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Connect-PnPOnline Connects to a SharePoint site and creates a context that is required for the other PnP Cmdlets Get-Help Connect-PnPOnline –Examples Get-Help Connect-PnPOnline –Detailed 19
  • 21. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Get/Set-PnPContext Sets the context to use by the cmdlets • Useful for switching between sites Connect-PnPOnline –Url $siteAurl –Credentials $Credentials $ctx = Get-PnPContext Get-PnPList Connect-PnPOnline –Url $siteBurl –Credentials $Credentials Get-PnPList Set-PnPContext Get-PnPList 20
  • 22. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Extract Template Write-Output "Creating PnP template..."; #Include necessary parameters Get-PnPProvisioningTemplate -PersistBrandingFiles -PersistPublishingFiles -IncludeSiteGroups -Out $path; Write-Output $("Template saved to {0}" -f $path); 21
  • 23. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Parameters Get-PnpProvisioningTemplate parameters included in script 22 Parameter Type Required Description IncludeSiteGroups SwitchParameter False If specified all site groups will be included. PersistBrandingFiles SwitchParameter False If specified the files used for masterpages, sitelogo, alternate CSS and the files that make up the composed look will be saved. PersistPublishingFiles SwitchParameter False If specified the files used for the publishing feature will be saved.
  • 24. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Get Context (Target Site) $webUrl = "https://{0}.sharepoint.com{1}/" -f $tenant, $targetSite; Write-Output $("Connecting to {0}..." -f $webUrl); Connect-PnPOnline -Url $webUrl -Credentials $credential; Write-Output "Done"; 23
  • 25. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Create New Sub-site #Change the Locale ID if necessary #Change the Site Template if necessary $web = New-PnPWeb -Title "<sitetitle>" -Url $subSite -Description "<sitedescription>" -Locale 1033 -Template "<Site Template>"; or $web = New-PnPWeb -Title $siteTitle -Url $subSite -Description $siteDescription -Locale 1033 -Template "<Site Template>"; 24
  • 26. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Get Context (Sub-site) $webUrl = "https://{0}.sharepoint.com{1}/" -f $tenant, $subSite; Write-Output $("Connecting to {0}..." -f $webUrl); Connect-PnPOnline -Url $webUrl -Credentials $credential; Write-Output "Done"; 25
  • 27. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Turn On TraceLog Set-PnPTraceLog -on -level debug 26
  • 28. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Apply Template Write-Output $("Applying PnP template [{0}] to site [{1} ({2})]..." -f $path, $web.Title, $web.Url); Apply-PnPProvisioningTemplate -Path $path; Write-Output "Done"; 27
  • 29. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Disconnect Disconnect-PnPOnline 28
  • 30. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. 29 Working Through Script Errors
  • 31. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Site Collection Features Issue: • Site collections features that are activated on the source site collection but not the target site collection can cause applying the template to fail, with error “Feature with Id <featureID>' is not installed in this farm, and cannot be added to this scope.” Example: • Feature with Id '863b4392-e4a4-460e-ae8d-14c29b14f14a' is not installed in this farm, and cannot be added to this scope. Solution: • Compare the site collection features from the source site collection to the target site collection • On the target site collection, activate any site collection features that are activated on the source site collection 30
  • 32. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Site Features Issue: • Site features that are activated on the source site but not the target site can cause applying the template to fail, with an error of feature missing Solution: • Compare the site features from the source site to the target site • On the target site, activate any site features that are activated on the source site • In the template XML file, delete the feature that “is not installed in this farm, and cannot be added to this scope” 31
  • 33. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Error Updating Field Updating field 413213c2-3e91-4dc8-9d47-216b83ab8027 failed: The field was found invalid: {{listid:Deliverables} • Search the Internet for “SharePoint [field ID]” • Go to the list settings and click on the field to open it or • Delete the column or list o Re-create it manually or let the script re-create it 32
  • 34. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Content Types (1/2) Error: • Referenced content type 0x01010029AB996A778A324EAEF918C866ECBD19 not available in site or in template Solution: • Copy the Content Type ID from the PowerShell window and search for it in the template • Delete document-specific content type IDs from the template XML file o Happens because content is not copied from original site to new site 33
  • 35. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Content Types (2/2) Resources: • Content Type IDs https://msdn.microsoft.com/en- us/library/office/aa543822(v=office.14).aspx • Base Content Type Hierarchy https://msdn.microsoft.com/en- us/library/office/ms452896(v=office.14).aspx 34
  • 36. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Source Site Target Site Default Content Type Not Updated 35
  • 37. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Can’t Customize Permission Levels (1/2) Apply-PnPProvisioningTemplate : You cannot customize permission levels in a web site with inherited permission levels. 36
  • 38. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Can’t Customize Permission Levels (2/2) 37
  • 39. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. All Sitegroups WARNING: You are requesting to export sitegroups from a subweb. Notice that ALL sitegroups from the site collection are included in the result. 38
  • 40. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Connection Closed by the Server Get-PnPProvisioningTemplate : The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. 39
  • 41. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Error with Argument (1/2) The argument must be a single file name and cannot contain path characters 40
  • 42. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Error with Argument (2/2) Trying to create a master page library at the subsite level • Master pages are stored at the site collection level • Unnecessary for a subsite 41
  • 43. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Specified Argument Out of Range Apply-PnPProvisioningTemplate : Specified argument was out of the range of valid values. • Not the Cause: OOTB web part (Newsfeed) was removed from homepage 42
  • 44. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Custom Web Parts Purchased/downloaded from SharePoint Store Delete code from XML file 43
  • 45. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Copy File Copy-PnPFile -SourceUrl <relativeURL/filename.extension> -TargetUrl <relative URL> • Copy site logos and other pictures or files that are needed on each site 44
  • 46. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. 45 Resources
  • 48. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Resources https://dev.office.com/patterns-and-practices How to get started with Office Dev PnP web cast SharePoint PnP Webcast – What should SharePoint Administrators know about SharePoint Framework? https://github.com/SharePoint/PnP PnP PowerShell – GitHub repository SharePoint Online Management Shell Windows Management Framework Cmdlet Documentation 47
  • 49. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Special Thanks To… Antii K. Koskela (@koskila) Eric Skaggs (@skaggsej) Eric Overfield (@ericoverfield) Erwin van Hunen (@erwinvanhunen) Nick van Denheuvel @officedevpnp 48
  • 50. Confidential and Proprietary Information – Property of PinnacleART. Any attempt to procure, use or disclose is strictly prohibited. Questions? Theresa Eller @SharePointMadam | sharepointmadam@gmail.com sharepointmadam.blogspot.com | slideshare.net/sharepointmadam