1

I was researching for add/edit/delete Site Policy in SharePoint Online with PowerShell/REST but with no luck.

Is it possible with SharePoint Online with PowerShell/CSOM?

1 Answer 1

1

CSOM for SharePoint online contains the Microsoft.SharePoint.Client.InformationPolicy namespace which contains the API for handling the site policies.

You can use it by adding the reference to the Microsoft.Office.Client.Policy.dll and adding

using Microsoft.SharePoint.Client.InformationPolicy;

to your class.

ProjectPolicy.GetProjectPolicies method can be used to retreive all the defined policies.

Here's simple c# code for listing all the policies defined on the site collection (I'm assuming here that you have already connected to the site using the csom):

var policies = ProjectPolicy.GetProjectPolicies(context, web);
context.Load(policies);
context.ExecuteQuery();

//For example the policies.Count property would give you the count of the defined policies. 
//This should list all the policies names:
foreach(var p in policies)
{
    Console.WriteLine(p.Name);
}  

ProjectPolicy.ApplyProjectPolicy method can be used for applying the policy to the appropriate site.

EDIT (based on the OP's comment): Unfortunately, it is currently not possible to create site policies using the API. Here's the PnP Github page which states this.

4
  • Thanks, @Damjan. When I connected to Content Type Hub Site I was able to see all policies but I do not see any API to Add/Edit/Delete Policy. I would really appreciate if you can help. Commented Jan 2, 2019 at 23:51
  • That is currently not possible. Please check my updated answer. Commented Jan 3, 2019 at 17:24
  • Thanks, @Damjan. One last question, is there RestAPI available to fetch all site policy or CSOM is the only option? Commented Jan 7, 2019 at 18:00
  • No, unfortunately the Rest API for fetching the policies doesn't seem to exist, so the CSOM is currently your only option there. Commented Jan 7, 2019 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.