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
cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
Start-SPAssignment -Global
# varable description
$webUrl = "http://test.site.com"
$web = Get-SPWeb $webUrl
$libraryName = "Test Document Library"
$libraryDescription = "Test Documents"
$libraryTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary;
# Adding Library
try
{
#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"
}
else
{
$web.Lists.Add($libraryName,$libraryDescription,$libraryTemplate);
$web.Update()
write-host -f green $libraryName "has been Successfully created in the site"
}
}
catch
{
write-host "Error" $_.exception
$errorlabel = $true
}
finally
{
Stop-SPAssignment -Global
if($web -ne $null)
{
$web.Dispose()
}
write-host "press any key to continue"
$a = read-host
}
#SharePoint Create Document Library Using PowerShell
cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
Start-SPAssignment -Global
# varable description
$webUrl = "http://test.site.com"
$web = Get-SPWeb $webUrl
$libraryName = "Test Document Library"
$libraryDescription = "Test Documents"
$libraryTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary;
# Adding Library
try
{
#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"
}
else
{
$web.Lists.Add($libraryName,$libraryDescription,$libraryTemplate);
$web.Update()
write-host -f green $libraryName "has been Successfully created in the site"
}
}
catch
{
write-host "Error" $_.exception
$errorlabel = $true
}
finally
{
Stop-SPAssignment -Global
if($web -ne $null)
{
$web.Dispose()
}
write-host "press any key to continue"
$a = read-host
}
No comments:
Post a Comment