[玩转系统] SharePoint Online:使用 PowerShell 创建多个文档库
作者:精品下载站 日期:2024-12-14 21:09:29 浏览:14 分类:玩电脑
SharePoint Online:使用 PowerShell 创建多个文档库
要求:使用 PowerShell 在 SharePoint Online 中创建多个文档库。
如何在SharePoint Online中创建多个文档库?
您是否希望在 SharePoint Online 中创建多个文档库?单个文档库可能并不总是足够的。也许您想为公司的每个部门创建一个库或单独的 SharePoint 库来存储您正在处理的不同项目的文件,或者您可能有大量需要组织的文档。无论出于何种原因,创建多个文档库都是管理文件、保证文件安全并充分利用 SharePoint 文档管理的最佳实践。在本指南中,我们将向您展示如何通过 PowerShell(一种用于自动化任务的脚本语言)在 SharePoint Online 中创建多个文档库!
有时,默认库“文档”可能不够,您可能需要向网站添加其他文档库。假设您拥有网站的编辑权限(或网站所有者或网站成员组的成员),则在 SharePoint Online 中创建多个文档库非常简单,只需几个简单的步骤即可完成:
对您想要创建的每个其他库重复这些步骤。创建文档库后,您可以将新文件(几乎所有文件类型)上传到其中或创建新文件夹以帮助组织文档。您还可以为团队成员或员工设置权限,并控制谁有权访问您的文档库,并通过库设置添加字段、内容类型、设置权限继承、版本历史记录、工作流程等来进一步自定义库。
PowerShell 在 SharePoint Online 中创建多个文档库
Microsoft SharePoint 是一个多功能平台,可用于以各种方式管理和共享数据以进行协作。 SharePoint 团队网站附带一个名为“文档”的默认文档库。您是否经常定期创建文档库?使用 PowerShell,您可以立即创建多个文档库,这是一次批量配置文档库的好方法。
如何在SharePoint Online中创建多个文档库?我们可以通过将脚本包装到可重用函数中并使用要创建的文档库数组调用该函数来创建多个文档库。
SharePoint 中的文档库数量有限制吗?一个 SharePoint 网站可以有多少个库?从技术上讲,每个网站集(包括根网站和任何子网站)可以组合 2000 个列表和库。由于 5000 的列表视图阈值限制会影响 SharePoint Online 中的性能和可用性,因此最好创建多个文档库。
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to Create a SharePoint Online document library
Function CreateSPO-DocumentLibrary()
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$True,ValueFromPipeline)] [String[]] $LibraryNames,
[Parameter(Mandatory=$False)] [String] $Description
)
Try {
#Create Each Document Library
ForEach($LibraryName in $LibraryNames)
{
Write-host -f Yellow "`nEnsuring Document Library '$LibraryName'"
#Get All Existing Lists from the web
$Lists = $Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()
#Check if Library name doesn't exist already
If(!($Lists.Title -contains $LibraryName))
{
#Create a new Document Library
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $LibraryName
$ListInfo.Description = $Description
$ListInfo.TemplateType = [Microsoft.SharePoint.Client.ListTemplateType]::DocumentLibrary
$Web.Lists.Add($ListInfo) | Out-Null
$Ctx.ExecuteQuery()
write-host -f Green "`tNew Document Library '$LibraryName' has been created!"
}
Else
{
Write-Host -f Magenta "`tA Document Library '$LibraryName' Already exists!"
}
}
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
}
#Set Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"
#Get Credentials to connect
$Cred = Get-Credential
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the web from URL
$Web = $Ctx.web
$Ctx.Load($Web)
$Ctx.executeQuery()
#Call the function to create document libraries
CreateSPO-DocumentLibrary -LibraryNames @("Document Library 1", "Document Library 2", "Document Library 3", "Document Library 4")
使用 PowerShell 在 SharePoint Online 中创建多个文档库
如果您想向批量文档库脚本添加一些附加参数(例如“快速启动”)怎么办?这是我的 CSV 文件,其中包含文档库详细信息。
您可以在此处下载 CSV 模板:
让我们使用 PowerShell 从 CSV 文件创建单独的文档库:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to Create a SharePoint Online document library
Function CreateSPO-DocumentLibrary()
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$True,ValueFromPipeline)] [String] $LibraryName,
[Parameter(Mandatory=$False)] [String] $Description,
[Parameter(Mandatory=$False)] [Switch] $ShowOnQuickLaunch
)
Try {
Write-host -f Yellow "`nEnsuring Document Library '$LibraryName'"
#Get All Existing Lists from the web
$Lists = $Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()
#Check if Library name doesn't exist already
If(!($Lists.Title -contains $LibraryName))
{
#Set Quick Launch Option
If($ShowOnQuickLaunch.IsPresent)
{
$QuickLaunchOption = [Microsoft.SharePoint.Client.QuickLaunchOptions]::On
}
Else
{
$QuickLaunchOption = [Microsoft.SharePoint.Client.QuickLaunchOptions]::Off
}
#Create Document Library
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $LibraryName
$ListInfo.Description = $Description
$ListInfo.TemplateType = [Microsoft.SharePoint.Client.ListTemplateType]::DocumentLibrary
$List = $Web.Lists.Add($ListInfo)
$List.OnQuickLaunch = $QuickLaunchOption
$List.Update()
$Ctx.ExecuteQuery()
write-host -f Green "`tNew Document Library '$LibraryName' has been created!"
}
Else
{
Write-Host -f Magenta "`tA Document Library '$LibraryName' Already exists!"
}
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
}
#Set Parameters
$CSVFilePath = "C:\Temp\DocLibs.csv"
#Get Credentials to connect
$Cred = Get-Credential
#Get the CSV file
$CSVFile = Import-Csv $CSVFilePath
#Read CSV file and create a document library
ForEach($Line in $CSVFile)
{
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Line.SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the web from URL
$Web = $Ctx.web
$Ctx.Load($Web)
$Ctx.executeQuery()
#Get the ShowOnQuickLaunch option
$ShowOnQuickLaunch = [System.Convert]::ToBoolean($Line.ShowOnQuickLaunch)
#Call the function to create document library
If($ShowOnQuickLaunch -eq $True)
{
CreateSPO-DocumentLibrary -LibraryName $Line.LibraryName -Description $Line.Description -ShowOnQuickLaunch
}
Else
{
CreateSPO-DocumentLibrary -LibraryName $Line.LibraryName -Description $Line.Description
}
}
“TemplateType”参数定义库的类型。使用“[Microsoft.SharePoint.Client.ListTemplateType].GetEnumNames()”获取可在 SharePoint Online 中创建的所有可用列表和库。例如,图片库、公告等。
使用 PnP PowerShell 批量创建文档库
这次,我必须从一个 CSV 文件创建多个文档库,并设置文档库的特定属性,例如设置版本控制(主要版本-次要版本)、列出经验和权限!该 CSV 文件有两列:LoginID 和 DisplayName。
使用此 PowerShell 从 CSV 文件输入批量创建文档库。
#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Shared"
$CSVFilePath = "C:\Users\salaudeen\Documents\Users.csv"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the CSV file
$CSVFile = Import-Csv $CSVFilePath
#Read CSV file and create new library
ForEach($Line in $CSVFile)
{
Try {
#Create document library
Write-host -f Yellow "Creating Document Library:"$Line.DisplayName
New-PnPList -Title $Line.DisplayName -Template DocumentLibrary -Url $Line.LoginID -ErrorAction Stop
#Set Library Properties
Set-PnPList -Identity $Line.DisplayName -EnableVersioning $True -EnableMinorVersions $True -CopyRoleAssignments:$False -BreakRoleInheritance -ListExperience NewExperience
$Library = Get-PnPList -Identity $Line.DisplayName
#Exclude from Search Results
$Library.NoCrawl = $True
$Library.Update()
#Grant permission on List to User
$UserID = $Line.LoginID+"@crescent.com"
Set-PnPListPermission -Identity $Line.DisplayName -AddRole "Full Control" -User $UserID
Write-host -f Green "`tCreated Document Library:"$Line.DisplayName
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
}
您也可以在 OneDrive 网站上使用这些脚本。
文件夹仍然比元数据更广泛使用。要在 SharePoint 文档库中创建多个文件夹,请使用:如何将文件夹批量添加到 SharePoint Online?
结论
总之,在 SharePoint Online 中创建多个文档库是一个简单明了的过程,可以通过 PowerShell 执行。通过使用这种方法,您可以有效地管理和组织您的SharePoint内容和信息,保证业务需求,例如每个部门或团队都有一个单独的库来存储文件和文档。借助触手可及的 SharePoint Online 和 PowerShell 的强大功能,您可以简化内容管理任务,并确保您的网站井井有条并可根据需要进行访问。
经常问的问题:
如何使用 PowerShell 获取 SharePoint Online 中的文档库?
使用:Get-PnPList -Identity“DocumentLibraryName”从 SharePoint Online 网站获取任何文档库。您还可以使用 CSOM PowerShell 脚本 $Ctx.Web.Lists.GetByTitle(“DocumentLibraryName”) 来获取库。
详细信息:使用 PowerShell 在 SharePoint Online 中获取文档库
如何使用 PowerShell 获取 SharePoint Online 文档库中的文件列表?
您可以使用 CSOM 或 PnP PowerShell 脚本获取 SharePoint Online 文档库中所有文件的列表,并将清单导出到 CSV 文件。
详细信息:如何获取 SharePoint Online 文档中的文件列表图书馆?
如何更改SharePoint在线文档库URL?
若要更改文档库的 URL,您可以使用文件浏览视图、SharePoint Designer 或 PowerShell 方法。
详细信息:在 SharePoint Online 中重命名文档库 URL
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag