SharePoint Online: Disable Attachment in List using PowerShell

Requirement: Disable Attachment in SharePoint Online List

How to Disable Attachment 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. To disable attachments in the SharePoint Online list, Go to the List Settings >>Advanced Settings >> Set the “Disable” option for Attachments!

sharepoint online disable attachments in list using powershell

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

SharePoint Online: PowerShell to Disable Attachments in a List

We can turn off attachments in SharePoint Online list with PowerShell as well:

#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
        #Disable List Attachments

        #Apply the settings to list
        Write-host -f Green "Attachments Disabled in List:"$ListName
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
#Set Config Parameters

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

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

Disable Attachments in List using PnP PowerShell

To remove attachments from SharePoint Online list, we can use this PowerShell:

#Config Variables
$SiteURL = ""
$ListName ="Projects"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

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

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

One thought 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?


Leave a Reply