none
Set RMS settings on SharePoint Online Library.

    Question

  • How can i use CSOM  to work in SharePoint online script. Here's my script it executes with out errors but doesnt set IRM settings in SharePoint online library.

    $site = "https://Domain.sharepoint.com/sites/****"
    $Context = Get-ClientContext $Username $password $site
    $list = $Context.Web.Lists
    $context.Load($list)
    $context.ExecuteQuery()
    Foreach($lists in $list)
    {
     if($lists.BaseType -eq "DocumentLibrary" -and $lists.Hidden -eq $false)
     {
     write-host $lists
     set-SPOList -ListName $lists
    $lists.IrmEnabled =$true
     $lists.InformationRightsManagementSettings.PolicyTitle = "RMSDefaultPolicy"
     $lists.InformationRightsManagementSettings.PolicyDescription = "Default RMS Policy"
      $lists.InformationRightsManagementSettings.AllowPrint = $true
    $lists.InformationRightsManagementSettings.EnableLicenseCacheExpire = $true
    $lists.InformationRightsManagementSettings.LicenseCacheExpireDays = "8" 
    $lists.Update()
    write-Host $lists.Title + "hi"
    }

    }

    Any help is appreciated!


    • Edited by Jain, Vijay Saturday, March 18, 2017 2:44 AM
    Saturday, March 18, 2017 2:42 AM

Answers

  • I think you are missing one more .ExecuteQuery()  after Update()

    Can you try the following:

      $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
      $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
      $ctx.Load($ctx.Web)
      $ctx.ExecuteQuery()
      $lls=$ctx.Web.Lists
      $ctx.Load($lls)
      $ctx.ExecuteQuery()
    
    
      foreach($ll in $lls)
      {
      Write-Host $ll.irmenabled
      $ll.IrmEnabled=$false
      $ll.Update()
      $ctx.ExecuteQuery()
      }

    • Marked as answer by Jain, Vijay Monday, March 20, 2017 6:32 PM
    Monday, March 20, 2017 11:48 AM

All replies

  • I think you are missing one more .ExecuteQuery()  after Update()

    Can you try the following:

      $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
      $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
      $ctx.Load($ctx.Web)
      $ctx.ExecuteQuery()
      $lls=$ctx.Web.Lists
      $ctx.Load($lls)
      $ctx.ExecuteQuery()
    
    
      foreach($ll in $lls)
      {
      Write-Host $ll.irmenabled
      $ll.IrmEnabled=$false
      $ll.Update()
      $ctx.ExecuteQuery()
      }

    • Marked as answer by Jain, Vijay Monday, March 20, 2017 6:32 PM
    Monday, March 20, 2017 11:48 AM
  • Hi Arleta Wanat,

    It worked!Thank you very much!

    Monday, March 20, 2017 6:32 PM