|
1 | 1 | --- |
2 | 2 | layout: page |
3 | | -title: 'Enable attachments' |
| 3 | +title: 'Disable attachments in SharePoint list' |
4 | 4 | hero_image: '/img/IMG_20220521_140146.jpg' |
5 | 5 | show_sidebar: false |
6 | 6 | hero_height: is-small |
7 | 7 | date: '2025-02-09' |
8 | | ---- |
| 8 | +--- |
| 9 | + |
| 10 | + |
| 11 | +# Disable attachments in your SharePoint lists |
| 12 | + |
| 13 | +Modern SharePoint lists often allow users to attach files to list items. However, in certain scenarios, you might want to disable this feature to maintain a cleaner or more secure list environment. For example, if your list is used purely for tracking text-based data, attachments might be unnecessary or even counterproductive. |
| 14 | + |
| 15 | +## User Interface |
| 16 | + |
| 17 | +You can disable the attachments in your SharePoint list directly in the browser and for a single list I would recommend this approach |
| 18 | + |
| 19 | +[](https://youtu.be/i8In3duIdq0 "Video Title") |
| 20 | + |
| 21 | + |
| 22 | +test |
| 23 | + |
| 24 | + |
| 25 | +<video src="https://youtu.be/i8In3duIdq0" controls></video> |
| 26 | + |
| 27 | +## Powershell |
| 28 | + |
| 29 | + |
| 30 | +With PowerShell and the PnP module, disabling attachments in a SharePoint list is simple. Here’s the command to achieve this: |
| 31 | + |
| 32 | +```powershell |
| 33 | +
|
| 34 | +Set-PnPList -Identity "Demo List" -EnableAttachments $false |
| 35 | +
|
| 36 | +``` |
| 37 | + |
| 38 | +This script disables the attachment feature for the specified list, replacing "Demo List" with the name of your target list. Make sure you are connected to your SharePoint site using the Connect-PnPOnline cmdlet before running this command. |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +### For all lists in one site collection |
| 43 | + |
| 44 | +```powershell |
| 45 | +
|
| 46 | +# Connect to the SharePoint site collection |
| 47 | +Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -UseWebLogin |
| 48 | +
|
| 49 | +# Get all lists in the site |
| 50 | +$lists = Get-PnPList |
| 51 | +
|
| 52 | +# Disable attachments for all lists |
| 53 | +foreach ($list in $lists) { |
| 54 | + Set-PnPList -Identity $list.Title -EnableAttachments $false |
| 55 | +} |
| 56 | +
|
| 57 | +Write-Host "Attachments have been disabled for all lists in the site collection." |
| 58 | +
|
| 59 | +``` |
| 60 | + |
| 61 | + |
| 62 | +### For all site collections (the entire tenant) |
| 63 | + |
| 64 | +The script below disables attachments on all lists in the entire Microsoft 365 tenant. Mind you, Teams are also SharePoint sites! |
| 65 | + |
| 66 | +```powershell |
| 67 | +
|
| 68 | +# Connect to the SharePoint Admin Center |
| 69 | +Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -UseWebLogin |
| 70 | +
|
| 71 | +# Get all site collections in the tenant |
| 72 | +$sites = Get-PnPTenantSite -IncludeOneDriveSites $false |
| 73 | +
|
| 74 | +foreach ($site in $sites) { |
| 75 | + Write-Host "Processing site: $($site.Url)" |
| 76 | + |
| 77 | + # Connect to each site |
| 78 | + Connect-PnPOnline -Url $site.Url -UseWebLogin |
| 79 | + |
| 80 | + # Get all lists in the site |
| 81 | + $lists = Get-PnPList |
| 82 | + |
| 83 | + # Disable attachments for all lists in the site |
| 84 | + foreach ($list in $lists) { |
| 85 | + if ($list.BaseTemplate -eq 100) { # Only target custom lists |
| 86 | + Set-PnPList -Identity $list.Title -EnableAttachments $false |
| 87 | + Write-Host "Disabled attachments for list: $($list.Title)" |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | +
|
| 92 | +Write-Host "Attachments have been disabled for all lists in all sites." |
| 93 | +
|
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | +## Github |
| 98 | + |
| 99 | +For older SharePoint versions and CSOM have a look at my other scripts at [Github](https://github.com/PowershellScripts/SharePointOnline-ScriptSamples/tree/develop/Items%20Management/Attachments) |
| 100 | + |
0 commit comments