kwizcom banner advertisement

SharePoint Online: Disable Attachment in List using PowerShell

Requirement: Disable Attachment in SharePoint Online List

How to Disable Attachment in SharePoint List?
To disable attachments in SharePoint Online list, Go to the List Settings >>Advanced Settings >> Set "Disable" option for Attachments!
sharepoint online disable attachments in list using powershell

SharePoint Online: PowerShell to Disable Attachments in a List
#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://crescenttech.sharepoint.com"
$ListName="Projects"

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

Disable Attachments in List using PnP PowerShell
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com"
$ListName ="Projects"

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

#Disable Attachments
Set-PnPList -Identity $ListName -EnableAttachments $False
SharePoint Online: Disable Attachment in List using PowerShell SharePoint Online: Disable Attachment in List using PowerShell Reviewed by Salaudeen Rajack on April 09, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.