当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 在 SharePoint 中创建文档库

作者:精品下载站 日期:2024-12-14 21:01:28 浏览:15 分类:玩电脑

使用 PowerShell 在 SharePoint 中创建文档库


要求:使用 PowerShell 在 SharePoint 2013/2016 中创建文档库。

用于在 SharePoint 中创建新文档库的 PowerShell 脚本:

您是否正在寻找使用 PowerShell 在 SharePoint 中创建文档库的方法?在这篇文章中,我将向您展示如何使用 PowerShell 在 SharePoint 中创建新的文档库。这对于自动化创建文档库的过程很有用。

以下是如何使用 PowerShell 在 SharePoint 2013 中创建文档库:


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#PowerShell Function to Create a Document Library in SharePoint 
Function Create-DocumentLibrary
{
 Param
 ( 
  [Microsoft.SharePoint.SPWeb]$Web,
  [String] $LibraryName,
  [String] $Description
 )
    #Get the Document Library template
    $ListTemplate = [Microsoft.Sharepoint.SPListTemplateType]::DocumentLibrary
  
    #Check if the library already exists
    if(($web.Lists.TryGetList($LibraryName)) -eq $null)
    {
        #Create the Library
        $Web.Lists.Add($LibraryName,$Description,$ListTemplate) > Null
   
        #Set Properties of Library such as OnQuickLaunch, etc
        $Library =  $Web.Lists[$LibraryName] 
        $Library.OnQuickLaunch = $true
        $Library.Update()
   
        Write-Host "Document library created successfully!" -f Green
    }
    else
    {
        Write-Host "Document Library '$LibraryName' already exists!" -f Red
    }
}
 
#Get the Web
$web = Get-SPWeb "https://intranet.crescent.com/"
 
#Call the function to create a library
Create-DocumentLibrary $web "Team Documents" "Library to Share Team Documents" 

此 PowerShell 脚本在 SharePoint 2013 中创建文档库。

[玩转系统] 使用 PowerShell 在 SharePoint 中创建文档库

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯