In this article we will define a template, and apply it for other SPO sites using PnP library
Please follow these steps :
- Set-up PnP module latest version from here https://github.com/SharePoint/PnP-PowerShell/releases
- Go to your SPO tenant, and create a SPO Site, you can also define (List structure, Theme, Pages, Content Types) because all of those will be part of the template.
- Make sure that the app catalog is activated on the tenant (There is no relation between app catalog and the tenant, but there is a bug found in January PnP package that required App catalog to be activated or a failure occurred)
- After having the site ready, run the below PowerShell command:
$Creds = Get-Credential
$SiteURL = "https://test.sharepoint.com/sites/demo1/"
Connect-PnPOnline -Url $SiteURL -Credentials $Creds
Get-PnPProvisioningTemplate -Out C:\temp\demo1Template.xml
- You should see a progress running for a while to export all settings.
- Please open the XML file at the provisioned path (C:\temp\demo1Template.xml), and have a look, it is also doable to do medications through the file, by adding items, or fields, but you need to be careful not to crap the schema.
- Now it is time to import it to the destination site, Create a destination site on SPO with a default teamsite template
- Apply the new template by running the below command.
$DestUrl = "https://test.sharepoint.com/sites/destination1/"
Connect-PnPOnline -Url $DestUrl -Credentials $Creds
$template = Load-PnPProvisioningTemplate -Path "C:\temp\demo1Template.xml"
Apply-PnPProvisioningTemplate -InputInstance $template
After this, refresh the destination site, and you should see the template applied.
I suggest to start first with a simple template, then apply more complexity to it. this approach should run smoothly also with SP2016, but I haven’t tried to import a template from SPO and import it to 2016 or vise versa
This script help you to upload your file or document to SharePoint library using PowerShell
- Download SharePoint Online client library from here , and install it. (If you already have it, please ignore this step)
- Create a folder named Temp on your C: drive, and put the Excel/CSV file in it
- Modify the parameters below and run the below script.
#Specify tenant admin and site URL
$User = "email@example.com"
$Password = "YourPassword"
$SiteURL = "https://tenantname.sharepoint.com/sites/site"
$Folder = "C:\Temp"
$DocLibName = "DocumentLibraryName"
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files (x86)\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files (x86)\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,(ConvertTo-SecureString $Password -AsPlainText -Force));
$Context.Credentials = $Creds
$List = $Context.Web.Lists.GetByTitle($DocLibName)
Foreach ($File in (dir $Folder -File))
$FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)