0

I have a question regarding the creating a Document Library based on the custom list definition, how can I do that using the PowerShell.

Thanks

3

In PowerShell you can add a library the same way as you would do in C# code

First you get the Web

$url =  "<url web>"
$web = Get-SPWeb $url

Then get the template name of a definition

To determine the name you can use someting like

$web.ListTemplates | Select Name, BaseType

Then take the name. The example below takes the document library definition and add a list based on that definition

$template = "Document Library"
$listTemplate = $web.ListTemplates[$Template]
$listurl = "<url list>"
$description = "<description>"
$web.Lists.Add($listUrl,$description,$listTemplate)
2

Try with the following code,

Add-PSSnapin Microsoft.Sharepoint.Powershell
    [CmdletBinding()]
    Param(
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [string]$Web,
    [Parameter(Mandatory=$true)]
    [string]$ListTitle,
    [Parameter(Mandatory=$true)]
    [string]$ListUrl,
    [Parameter(Mandatory=$false)]
    [string]$Description,
    [Parameter(Mandatory=$true)]
    [string]$Template
    )
Start-SPAssignment -Global
$SPWeb = Get-SPWeb -Identity $Web
$listTemplate = $SPWeb.ListTemplates[$Template]
$SPWeb.Lists.Add($ListUrl,$Description,$listTemplate)
$list = $SPWeb.Lists[$ListUrl] // ex: Lists["/pts/single/Pharma Docs"]
$list.Title = $ListTitle
$list.OnQuickLaunch = "True"
$list.Update()
$SPWeb.Dispose()
Stop-SPAssignment -Global
Remove-PsSnapin Microsoft.SharePoint.PowerShell

Source

0

Solved the issue with following code:

$workspace = $web.Webs[$workspaceURL]
$guid = $workspace.Lists.Add("CustomList", "", "CustomList", "632c2951-92c7-456e-b2e0-3034b80816be", "101", "101");
$workspace.Update();

Add functions, you provide the name, description, another name, GUID of the feature deploying list definition, type, type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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