0

I want to create an Asset Library on a Publish site collection.

I saw some articles saying to use BaseTemplate == 851. But no idea how to use it.

Here is the code I tried to create List

New-PnPList -Title "Contact Us Subjects" -Url "Lists/ContactUsSubjects" -Template GenericList 

But now I want to create a Asset Library using powershell. please help me

3
  • Is this what you are looking for you: c-sharpcorner.com/blogs/… Commented Feb 11, 2020 at 16:34
  • I tried that. It's not working.When getting Assets library template,it return null Commented Feb 11, 2020 at 17:28
  • anyone please help me? Commented Feb 12, 2020 at 7:54

1 Answer 1

0

Try the below command, for pnp powershell,

 New-PnPList -Title "Contact Us Subjects" -Url "Lists/ContactUsSubjects" -Template AssetLibrary 

Without pnp and using spo powershell, use the below code,

function CreateSPOList { #All the pre required variable to connect SPO. $strSiteURL = "<< Site URL >>" $strUsrName = "<< Site User ID >>" $strLstTitle = "Contact Us Subjects" $strLstDesc = "Contact Us Subjects!!!" $strLstTempID = 851 #Reading Password from end user $strPWD = Read-Host "Please enter the password for $($strUsrName)" -AsSecureString #Creating object to SPO with the provided user name and password $ObjSPOCredls = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($strUsrName, $strPWD) # Creating client context object with the provided user name and password $ObjContext = New-Object Microsoft.SharePoint.Client.ClientContext($strSiteURL) $ObjContext.credentials = $ObjSPOCredls #create asset library with the list template ID 851. (Asset library template) $ObjLstLoanDet = New-Object Microsoft.SharePoint.Client.ListCreationInformation $ObjLstLoanDet.title = $strLstTitle $ObjLstLoanDet.description = $strLstDesc $ObjLstLoanDet.TemplateType = $strLstTempID $ObjLst = $ObjContext.web.lists.add($ObjLstLoanDet) $ObjContext.load($ObjLst) # Sending request to SPO with all the pre loaded information. try{ $ObjContext.executeQuery() write-host "Successfully Creates List $($strLstTitle)" -foregroundcolor green } catch{ write-host "Error :: $($_.Exception.Message)" -foregroundcolor red } } CreateSPOList 
7
  • I tried this code, it's showing this error Cannot bind parameter 'Template'. Cannot convert value "AssetLibrary" to type "Microsoft.SharePoint.Client.ListTemplateType" Commented Feb 12, 2020 at 5:32
  • ok, then PnPList is referring to Microsoft.SharePoint.Client.ListTemplateType, which doesn't have a template definition for Asset library, check here docs.microsoft.com/en-us/previous-versions/office/… Commented Feb 12, 2020 at 5:52
  • Did you try the spo powershell code? Commented Feb 12, 2020 at 5:53
  • Yes I tried that, it's showing this error The Windows PowerShell snap-in 'Microsoft.SharePoint.PowerShell' is not installed on this computer I already installed Powershell Management tool. Commented Feb 12, 2020 at 5:56
  • Check this, stackoverflow.com/questions/43997587/… Commented Feb 12, 2020 at 6:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.