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

[玩转系统] SharePoint Online:使用 PowerShell 禁用列表中的附件

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

SharePoint Online:使用 PowerShell 禁用列表中的附件


要求:禁用 SharePoint Online 列表中的附件。

如何禁用 SharePoint Online 列表中的附件?

可以配置 SharePoint Online 列表以将文件附加到项目。默认情况下,附件选项配置为允许新列表。如果您不想让用户将文件附加到列表中的项目,您可以禁用它。这篇博文将向您展示如何使用 PowerShell 禁用列表中的附件,我们还将向您展示如何再次启用它。

要禁用 SharePoint Online 列表中的附件,请执行以下步骤:

  1. 导航到您要禁用附件的列表,然后单击右上角的“设置”齿轮图标。
  2. 单击下拉菜单中的“列表设置”可访问列表设置页面。
  3. 向下滚动到“常规设置”部分,然后单击“高级设置”。找到“附件”部分,然后为“列表项目的附件”选项选择“禁用”。
  4. 单击“确定”保存更改。

[玩转系统] SharePoint Online:使用 PowerShell 禁用列表中的附件

将附件设置为“禁用”状态后单击“确定”后,它将从列表中的所有项目中删除所有现有附件。

SharePoint Online:PowerShell 禁用列表中的附件

在 SharePoint Online 中,您可能希望禁用列表中的附件以防止用户将文件上传到列表。我们可以通过更新列表的“EnableAttachments”属性,使用 PowerShell 关闭 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 Disable-SPOListAttachment($SiteURL,$ListName) 
{
    Try { 
        #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)
 
        #Disable List Attachments
        $List.EnableAttachments=$False

        #Apply the settings to list
        $List.Update()
        $Ctx.ExecuteQuery()
 
        Write-host -f Green "Attachments Disabled in List:"$ListName
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}
#Set Config Parameters
$SiteURL="https://Crescent.sharepoint.com"
$ListName="Projects"

#Call the function to Disable Attachments in List
Disable-SPOListAttachment -SiteURL $SiteURL -ListName $ListName

要重新启用 SharePoint Online 列表中的附件,请设置:$List.EnableAttachments=$True

使用 PnP PowerShell 禁用列表中的附件

要从 SharePoint Online 列表中删除附件,我们可以使用此 PowerShell:


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

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

#Disable Attachments
Set-PnPList -Identity $ListName -EnableAttachments $False

要再次启用附件,请使用以下命令:


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

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

取消回复欢迎 发表评论:

关灯