Use CreateSharePointLibrary function to create a new SharePoint List or Library.
Parameters :
- $webUrl - Mandatory - SharePoint Web Url - e.g. http://server:port/
- $LibraryName - Mandatory - SharePoint Library Name
- $Discription - Mandatory - SharePoint Library Description
- $LibraryTemplate - Mandatory - SharePoint Library Template
function CreateSharePointLibrary
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string]$webUrl,
[Parameter(Mandatory=$true)]
[string]$LibraryName,
[Parameter(Mandatory=$true)]
[string]$Discription,
[Parameter(Mandatory=$false)]
[string]$LibraryTemplate
)
Start-SPAssignment -Global
$spWeb = Get-SPWeb -Identity $webUrl
$spListCollection = $spWeb.Lists
$spLibrary=$spWeb.Lists.TryGetList($LibraryName)
if($spLibrary -ne $null)
{
write-host -f yellow "Library $LibraryName already exists in the site"
}
else
{
Write-Host -NoNewLine -f yellow "Creating Library - $LibraryName"
$spListCollection.Add($LibraryName, $Discription, $LibraryTemplate)
$spLibrary = $spWeb.GetList("$LibraryName")
write-host -f Green "...Success!"
}
Stop-SPAssignment -Global
}
Function Calling -
$webUrl = "http://sever:port"
#-----------Document Library------------
$DocLibName = "DocLib1"
$LibraryTemplateDL = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
CreateSharePointLibrary $webUrl $DocLibName $DocLibName $LibraryTemplateDL
# -------Data Connection Library-----------
$DataConnLibName = "DataConnLib1"
$LibraryTemplateDCL = [Microsoft.SharePoint.SPListTemplateType]::DataConnectionLibrary
CreateSharePointLibrary $webUrl $DataConnLibName $DataConnLibName $LibraryTemplateDCL
Similarly you can create any type of SharePoint List or Libraries , here are the details of List/Library Templates -
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx
No comments:
Post a Comment