Creating document library to site using powershell script
[CmdletBinding()]
param ([Parameter(Mandatory=$true)] $SPSiteURL)
$ErrorActionPreference = "Stop"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function CreateSharePointFolder(
[Parameter(Mandatory=$true)] $SPWeb,
[Parameter(Mandatory=$true)] $ListTemplate,
[Parameter(Mandatory=$true)] $FolderName,
[Parameter(Mandatory=$true)] $Title,
[Parameter(Mandatory=$true)] $Description
)
{
$Folder = $spWeb.Lists.TryGetList($Title)
if($Folder -eq $NULL){
write-host "Creating new Document Library $Title"
$listId = $spWeb.Lists.Add($FolderName,$Description,$listTemplate)
$newList = $spWeb.Lists[$listId]
$newList.Title = $Title
$newList.OnQuickLaunch = "true"
$newList.Update()
}else
{
write-host "$Title already exists"
}
}
$spWeb = Get-SPWeb -Identity $SPSiteURL #http://splocal.ntlm
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
CreateSharePointFolder -ListTemplate $listTemplate -FolderName "prefix_entityname1" -Title "Entity Display Name1" -Description "Entity description" -SPWeb $spWeb
CreateSharePointFolder -ListTemplate $listTemplate -FolderName "prefix_entityname2" -Title "Entity Display Name2" -Description "Entity description" -SPWeb $spWeb
[CmdletBinding()]
param ([Parameter(Mandatory=$true)] $SPSiteURL)
$ErrorActionPreference = "Stop"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function CreateSharePointFolder(
[Parameter(Mandatory=$true)] $SPWeb,
[Parameter(Mandatory=$true)] $ListTemplate,
[Parameter(Mandatory=$true)] $FolderName,
[Parameter(Mandatory=$true)] $Title,
[Parameter(Mandatory=$true)] $Description
)
{
$Folder = $spWeb.Lists.TryGetList($Title)
if($Folder -eq $NULL){
write-host "Creating new Document Library $Title"
$listId = $spWeb.Lists.Add($FolderName,$Description,$listTemplate)
$newList = $spWeb.Lists[$listId]
$newList.Title = $Title
$newList.OnQuickLaunch = "true"
$newList.Update()
}else
{
write-host "$Title already exists"
}
}
$spWeb = Get-SPWeb -Identity $SPSiteURL #http://splocal.ntlm
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
CreateSharePointFolder -ListTemplate $listTemplate -FolderName "prefix_entityname1" -Title "Entity Display Name1" -Description "Entity description" -SPWeb $spWeb
CreateSharePointFolder -ListTemplate $listTemplate -FolderName "prefix_entityname2" -Title "Entity Display Name2" -Description "Entity description" -SPWeb $spWeb
No comments:
Post a Comment