SharePoint Online: How do I set the IRM settings for a Document Library in PowerShell?

I have used the CSOM approach to resolve the problem.

Here is an excellent post outlining the available methods that I based this script on.

Import-Module 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell' -DisableNameChecking

$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

$webUrl = "https://mytestsite.sharepoint.com/mysubsite"
$username = "richard.leeman@mysharepointonlinelogin.com"
$password = Read-Host -Prompt "Password for $username" -AsSecureString

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$web = $ctx.Web
$lists = $web.Lists

$ctx.Load($lists)
$ctx.Load($web)
$ctx.ExecuteQuery()

$list = $lists| Where-Object { $_.Title -eq "My Document Library"}

#enable permissions on the library
$list.IrmEnabled = $true
#title
$list.InformationRightsManagementSettings.PolicyTitle = "My title"
# description
$list.InformationRightsManagementSettings.PolicyDescription = "My description"
# reject items that do not support IRM
$list.IrmReject = $true
# expire the restriction
$list.IrmExpire = $true
$list.InformationRightsManagementSettings.DocumentLibraryProtectionExpireDate = "10/15/2015"
# disable opening documents in the browser
$list.InformationRightsManagementSettings.DisableDocumentBrowserView = $true
# allow users to print
$list.InformationRightsManagementSettings.AllowPrint = $true
# allow script script and screen reader functions to downloaded documents
$list.InformationRightsManagementSettings.AllowScript = $true
# allow viewers to write a copy of the downloaded documents
$list.InformationRightsManagementSettings.AllowWriteCopy = $true
# access rights expiry
$list.InformationRightsManagementSettings.EnableDocumentAccessExpire = $true
$list.InformationRightsManagementSettings.DocumentAccessExpireDays = "2" # between 1 and 365
# require credential verification
$list.InformationRightsManagementSettings.EnableLicenseCacheExpire = $true
$list.InformationRightsManagementSettings.LicenseCacheExpireDays = "4"
# Allow group protection
$list.InformationRightsManagementSettings.EnableGroupProtection = $true

$list.Update()
$ctx.ExecuteQuery()


Comments

Popular posts from this blog

SharePoint 2013: Error updating managed account credentials

How can I call a JIRA api through Powershell?