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:
- Navigate to the list you want to disable attachments and click on the “Settings” gear icon in the top-right corner.
- Click on “List settings” in the dropdown menu to access the list settings page.
- 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.
- Click “OK” to save your changes.
Once you click on “OK” after setting the attachments to the “Disabled” state, all existing attachments from all items in the list are deleted.
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 it. 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
While attachments can be a useful feature, there are scenarios where disabling them is necessary. For example, you might decide to remove the attachments and switch to using a dedicated document library for storing and managing related files.
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
How to Enable the Attachments in SharePoint List?
To enable attachments in a SharePoint list, follow these steps:
- Navigate to the SharePoint list where you want to enable attachments.
- Click on “Settings” (gear icon) in the upper-right corner, then choose “List settings” from the dropdown menu.
- Under the “General Settings” section, click on “Advanced settings.”
- Scroll down to the “Attachments” section.
- Select the “Yes” option to allow items in this list to have attachments.
- Scroll down and click “OK” to save the changes.
This will enable attachments for the list, allowing users to add files to list items.
PowerShell to Enable Attachments in SharePoint List
To enable the attachments in the SharePoint list again, use the following script:
#Enable Attachments
Set-PnPList -Identity $ListName -EnableAttachments $True
How to add an attachment column to the SharePoint list view?
You can add the attachment column to the default view by editing the current view and including the attachment column. Here is how to add the attachment column to the SharePoint list view, step-by-step:
- Go to your SharePoint list.
- Click on “Add column” then click on the “Show or hide columns” button.
- In the “Edit view” section, look for the checkbox named “Attachments” and ensure it is checked.
- Click “Apply” to save your changes.
Now, the attachment icon (a paperclip) will appear next to items in your list view that have attachments, allowing users to click on the icon to see or download attachments.
Conclusion
Whether you want to disable the attachments to promote structured data capture or enable them again, SharePoint provides the flexibility to adapt your list settings to meet your specific requirements. By following the step-by-step instructions provided in this guide, you’ll be able to disable and enable attachments in SharePoint lists.
but how can i get rid of the add attachment from new and edit item form?
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!).