I'm attempting to create a document library from a .stp template. To my knowledge the script worked and now its not. I get an error when the following is executed:

$ListCreation.ListTemplate = $ListTemplate

Exception setting "ListTemplate": "Cannot convert the "Microsoft.SharePoint.Client.ListTemplate" value of type "Microsoft.SharePoint.Client.ListTemplate" to type "Microsoft.SharePoint.Client.ListTemplate"."

I thought it may be the that I've referenced the wrong dll's .

Have re-installed:

  1. Microsoft.SharePoint.Client.dll v 16.0.6518.1200
  2. Microsoft.SharePoint.Client.Runtime.Portable.dll v 16.0.6518.1200

Any ideas on the error ?


2 Answers 2


You could re-install the SharePoint Online Client Components SDK and SharePoint Online Management Shell.

And there is a demo for your reference to create the document library from custom template by PnP PowerShell.

$username = "[email protected]"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr

$Url = "https://tenant.sharepoint.com/sites/tst" # URL of the site
$ListTemplateInternalName = "TestLibTemplate.stp" # Change this with your own list template
$ListName = "NewLibBaseonTemplate2" # Change this with the name of the list to be created

# Create list from template

Connect-PnPOnline -Url $Url -Credentials $cred

$Context = Get-PnPContext
$Web = $Context.Site.RootWeb
$ListTemplates = $Context.Site.GetCustomListTemplates($Web)

$ListTemplate = $ListTemplates | where { $_.InternalName -eq $ListTemplateInternalName }

if ($ListTemplate -eq $null)
    Throw [System.Exception] "Template not found"

$ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListCreation.Title = $ListName
$ListCreation.ListTemplate = $ListTemplate


Write-Host "Script complete"
  • Hi, Thats virtually the same code I am using. Same error persists. Oct 16, 2019 at 7:51
  • Did you re-install the SharePoint Online Client Components SDK and SharePoint Online Management Shell?
    – Amy_MSFT
    Oct 23, 2019 at 7:37

Without seeing more of your code I can't be sure of the error message, but here's how I did it:

$Installed=Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.PowerShell" }
if ($Installed -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" }

$SourceWebURL="http://<URL of site>"
$SourceWeb=Get-SPWeb -Identity $SourceWebURL
$NewLibrary="<Library Name>"
$TemplateName="<Template Name>"
$Template=$SourceWeb.Site.GetCustomListTemplates($SourceWeb) | Where-Object { $_.Name -eq $TemplateName }
$SourceWeb.Lists.Add($NewLibrary,$NewLibrary,$Template) > $null


  1. Local SharePoint
  2. Ran as credentials that already had sufficient permissions
  3. SharePoint 2019
  4. PowerShell 5.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.