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

[玩转系统] SharePoint Online:使用 PowerShell 配置列表设置

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

SharePoint Online:使用 PowerShell 配置列表设置


要求:使用 PowerShell 在 SharePoint Online 中编辑列表设置。

如何更改 SharePoint Online 中的列表设置?

SharePoint Online 中的列表设置定义列表的属性(例如名称、说明等)以及列表的功能。可以通过导航到列表设置页面来配置这些设置。这篇博文将逐步介绍配置列表设置所需的步骤。

要管理这些设置,请执行以下操作:

  1. 从设置 >> 列表设置导航到列表或库设置页面。列表或库的所有设置都位于该页面上。在此页面中,您可以配置列表名称、描述和导航选项。同样,版本控制、安全性等。

    [玩转系统] SharePoint Online:使用 PowerShell 配置列表设置

SharePoint Online:用于设置列表设置的 PowerShell

更新 SharePoint Online 中文档库的属性可以手动完成,但如果有多个库需要更新,则可能非常耗时。可以编写 PowerShell 脚本来自动执行此过程,并使其更快、更轻松。以下是用于更新 SharePoint Online 列表或库的最常见属性的 PowerShell:


#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"

#Set Config Parameters
$SiteURL="https://crescent.sharepoint.com/"
$ListName="Projects"

#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 List
$List=$Ctx.Web.Lists.GetByTitle($ListName)

#Allow management of content types? 
$List.ContentTypesEnabled=$True

#Make "New Folder" command available?
$List.EnableFolderCreation=$True

#Enable Attachments: Applicable Only for Lists!
$List.EnableAttachments=$True

#Require content approval for submitted items? 
$List.EnableModeration=$True

#Require documents to be checked out before they can be edited: Applicable Only for Libraries!
$List.ForceCheckout=$True

#Display this list using the new or classic experience? 
$List.ListExperienceOptions = "NewExperience" #ClassicExperience or Auto

#Draft Item Security
$List.DraftVersionVisibility = [Microsoft.SharePoint.Client.DraftVisibilityType]::Approver #Reader, Approver, Author

#Quick Edit - Allow items in this document library to be edited using Quick Edit and the Details Pane? 
$List.DisableGridEditing=$true

#Offline Client Availability 
$List.ExcludeFromOfflineClient = $True

#Apply the settings to list
$List.Update()
$Ctx.ExecuteQuery()

Write-host -f Green "List Settings Updated!"

您还可以使用此 PowerShell 脚本更新 SharePoint Online 中的文档库属性。

用于更新 SharePoint Online 中的文档库属性的 PnP PowerShell

要更新列表或文档库设置,我们可以通过 Set-PnPList cmdlet 使用这些 PnP PowerShell 脚本。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName ="Projects"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the List
$List = Get-PnPList -Identity $ListName

#powershell script to update document library properties in sharepoint online
If($List)
{ 
    #Enable versioning and set Number of versions to 50
    Set-PnPList -Identity $List -EnableVersioning $True -MajorVersions 50

    #Enable Content Type Management
    Set-PnPList -Identity $List -EnableContentTypes $True

    #Content Approval
    Set-PnPList -Identity $List -EnableModeration $True

    #Enable Folders
    Set-PnPList -Identity $List -EnableFolderCreation $True

    #Enable Attachments
    Set-PnPList -Identity $List -EnableAttachments $True 

    #Require Checkout
    Set-PnPList -Identity $List -ForceCheckout $True

    #Set List Experience
    Set-PnPList -Identity $List -ListExperience NewExperience
}

也可以将这些操作组合在一行中。例如。,


Set-PnPList -Identity $List -EnableAttachments $True -EnableContentTypes $True -EnableFolderCreation $True

请注意,PnP PowerShell 不提供 SharePoint Online 文档库或列表的所有可用属性的参数。因此,您可以使用以下内容:


#Config Variables
$SiteURL = "https://crescent.sharepoint.com"
$ListName ="Project Config"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the List
$List = Get-PnPList -Identity $ListName

#Set List Property
$List.Hidden = $True
$List.Update()
Invoke-PnPQuery

我关于使用 PowerShell 在 SharePoint Online 中配置列表设置的其他帖子:

  • SharePoint Online:使用 PowerShell 配置版本控制列表和库
  • SharePoint Online:通过使用 PowerShell 设置 NoCrawl 属性从搜索中删除列表
  • SharePoint Online:使用 PowerShell 设置列表标题、描述和快速启动导航选项

这是另一篇获取 SharePoint Online 列表设置的文章:SharePoint Online:PowerShell 获取列表设置

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

取消回复欢迎 发表评论:

关灯