Forum Discussion

Olaf Didszun's avatar
Olaf Didszun
Copper Contributor
Mar 22, 2017

Add new Site Policy in SharePoint Online by code

Hi there,

 

I am looking for a way to create a Site Policy in a SharePoint Online site collection by code (C# or PowerShell). I am wondering that for assigning a Site Policy to a site classes and methods are available in the CSOM, but there is nothing for creating the policies. And when there is anything, it's in a hidden place, where nobody can find it.

 

I have also tried to create the content type for the Site Policy by code to have a workaround, but the content type needs additional information in its XmlDocument member, but via Rest it is not possible to save this data.

 

The reason why I need the Site Policy is the site lifecycle, we need to implement. After a specific amount of time the site collection should be set into a read-only mode. The only way I see, is the Site Policy with its "The site collection will be read only when it is closed" setting. If there is any other way (no, removing the permissions is not a solution), then I maybe do not need the Site Policy.

 

Any hints are welcome. Maybe something for the PnP team (and they do a really good work!).

 

Thanks

Olaf

 

Resources