SharePoint Online: Disable Attachment in List using PowerShell

Requirement: Disable Attachment in SharePoint Online List.

How to Disable Attachments in SharePoint Online List?

A SharePoint Online list can be configured to attach files to the items. By default, the attachments option is configured to allow new lists. If you do not want to let users attach files to items in a list, you can disable it. This blog post will show you how to disable attachments in a list using PowerShell, and we will also show you how to enable it again.

To disable attachments in the SharePoint Online list, follow these steps:

  1. Navigate to the list you want to disable attachments and click on the “Settings” gear icon in the top-right corner.
  2. Click on “List settings” in the dropdown menu to access the list settings page.
  3. Scroll down to the “General Settings” section and click on “Advanced settings.” Find the “Attachments” section and select “Disabled” for the “Attachment to list items are” option.
  4. Click “OK” to save your changes.
sharepoint online disable attachments in list using powershell

Once you click on “OK” after setting the attachments to the “Disabled” state, it deletes all existing attachments from all items in the list.

SharePoint Online: PowerShell to Disable Attachments in a List

In SharePoint Online, you may want to disable attachments in a list to prevent users from uploading files to the list. We can turn off attachments in the SharePoint Online list with PowerShell, by updating the list’s “EnableAttachments” property.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\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

To Re-Enable the attachments in the SharePoint Online list, Set: $List.EnableAttachments = $True

Disable Attachments in List using PnP PowerShell

To remove attachments from the SharePoint Online list, we can use this 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

To enable the attachments again, use the following:

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “SharePoint Online: Disable Attachment in List using PowerShell

  • but how can i get rid of the add attachment from new and edit item form?

    Reply
    • If the attachment feature is disabled, you won’t get Attachments in New or Edit forms of the list (Unless your List forms are customized!).

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *