Search This Blog

Monday, May 26, 2014

PowerShell -SharePoint Create Document Library

Hi dude, Just copy paste the code in notepad and change site name , save it Lib.PS1 then execute.

#SharePoint Create Document Library Using PowerShell
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
Start-SPAssignment -Global

# varable description
$webUrl = ""
$web = Get-SPWeb $webUrl
$libraryName = "Test Document Library"
$libraryDescription = "Test Documents"
$libraryTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary;

# Adding Library
                #This will try to get the List/Library name and it will be used to check if list exists
                $list = $Web.Lists.TryGetList($libraryName)
                if($list -ne $null) #This will check if List/Library already exists
                write-host -f yellow $libraryName "already exists in site"
                write-host -f green $libraryName "has been Successfully created in the site"

    write-host "Error" $_.exception
    $errorlabel = $true

Stop-SPAssignment -Global
if($web -ne $null)
write-host "press any key to continue"
$a = read-host

No comments:

Post a Comment