{"id":1393,"date":"2018-05-16T21:20:30","date_gmt":"2018-05-16T20:20:30","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=1393"},"modified":"2018-05-16T21:20:30","modified_gmt":"2018-05-16T20:20:30","slug":"configuring-default-office-365-labels-using-powershell","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/","title":{"rendered":"Configuring default Office 365 Labels using PowerShell"},"content":{"rendered":"<h2>Office 365 Labels over Information Management Policies?<\/h2>\n<p>Office 365 labels are starting to get quite prolific across the stack now and I\u2019m starting to see better uses for them over SharePoint Retention policies. If you\u2019re not familiar with Office 365 labels, my MVP colleague Joanne Klein has a great blog post from last year that provides a <a href=\"https:\/\/joannecklein.com\/2017\/04\/30\/label-retention-across-o365\/\" target=\"_blank\" rel=\"noopener noreferrer\">great overview of the experience that you can read here<\/a>. Whilst you still can\u2019t trigger a retention off of a custom field with Labels, there\u2019s still some value in using them for simple retention policies and for triggering DLP actions. As part of a DMS project that I\u2019m working on, we needed to apply a default label to a number of libraries across SharePoint Online to ensure that content was automatically tagged with that label when uploaded or created.<\/p>\n<p>This is quite simple through the UI by selecting the \u201cApply Label to items in this list or library\u201d in the list settings. This displays the following dialogue that displays a list of all labels that have been published to that location. Whichever one is selected will automatically be applied to items created or uploaded to the library. You can also use the tick box to retrospectively apply the label to items that currently exist in the library, but be warned, this will automatically apply the label\u2019s retention policy next time the timer job runs, and any items that are past retention will be removed!<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"SNAGHTML51f9590\" src=\"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png\" alt=\"SNAGHTML51f9590\" width=\"759\" height=\"234\" border=\"0\" \/><\/a><\/p>\n<p>There\u2019s a few things that don\u2019t quite work for me at this point for more advanced scenarios, the key one being the ability to choose a default label per content type for a start as it\u2019s a much better way of attributing different retention policies across an information architecture and the second is of course the fact that labels can currently only trigger retention based on one of three dates, the Created Date, Modified Date and the Label Date (e.g. the date the label was applied).\u00a0 I think we\u2019re going to see a lot of development around this over the next 12 to 18 months however, so I don\u2019t think we\u2019re stuck with this for long!<\/p>\n<h2>Applying this through script<\/h2>\n<p>In my scenario though, the basic default label actually worked really well for a large number of libraries in the solution I was building.. and when I say large number, I\u2019m talking around 2000 libraries, so you can imagine that we didn\u2019t want to have to visit each of these libraries in turn to configure the policy. I did some investigation and had a discussion with a number of other MVPs and we all came to the same conclusion that whilst the option was there in the schema and available on the ListItem object, the equivalent List object property wasn\u2019t exposed through CSOM to enable this to be configured by code.<\/p>\n<p>I posted my woes onto the Microsoft Tech Community site and highlighted the post to a few people in the MS SharePoint world to see if I could get some comment. Mikael Svenson who had been looking at the issue with me also raised a <a href=\"http:\/\/sharepoint.uservoice.com\" target=\"_blank\" rel=\"noopener noreferrer\">User Voice<\/a> (<em>which is absolutely one of the best ways of getting Microsoft\u2019s attention these days on requests for features!<\/em>) and at that point I decided to return to the fall back approach of using an IE session controlled by PowerShell to screen scrape and re-create the clicks that a user would do, through script. Not my favourite approach, but it does work!<\/p>\n<p>Whilst I was doing this though, Mikael sent me a message to say that there was a new release of the CSOM code and it included the ability to set this label through the List object. I took a look, and tested it and sure enough, setting this label became very easy indeed! So massive Kudos to Microsoft Engineering for turning this around so quickly.<\/p>\n<p>To have a play with this, you\u2019ll need the latest CSOM binaries (You really should be using NUGET to keep these up to date too!), you\u2019ll need the version MIcrosoft.SharePointOnline.CSOM.16.1.7521.1200 at least and you\u2019ll need to load the Microsoft.Office.Client.Policy.dll into your script.<\/p>\n<p>Once you have a context object, you can get a list of the tags that are currently published to the site using:<\/p>\n<pre class=\"brush: ps;\">[Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy]::GetAvailableTagsForSite($SPOContext,$SPOContext.Url)\r\n$SPOContext.ExecuteQuery()<\/pre>\n<p>This returns a collection of labels (Object ComplianceTag) that are available, if you have a reference to the Root Folder object of a library, you can query it to find out what the current label setting is:<\/p>\n<pre class=\"brush: ps;\">$CurrentLabelApplied = [Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy]::GetListComplianceTag($SPOContext,$docLibRoot.ServerRelativeUrl)\r\n$SPOContext.ExecuteQuery()<\/pre>\n<p>This returns a single label object of type ComplianceTag.<\/p>\n<p>To set the compliance tag on the library, you just need the TagName of the require ComplianceTag.<\/p>\n<pre class=\"brush: ps;\">[Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy]::SetListComplianceTag($SPOContext,$docLibRoot.ServerRelativeUrl,\"Default Label Tag Name\",$false, $false,$false)\r\n$SPOContext.ExecuteQuery()<\/pre>\n<p>A nice simple command with a couple of arguments, the most of which are self explanatory, apart from the last three which relate to making the tag deletable or editable but also appear to have no effect at all. Unfortunately there\u2019s no documentation just yet on these, but I\u2019ll update this post as and when it appears.<\/p>\n<p>&nbsp;<\/p>\n<p>Paul.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Office 365 Labels over Information Management Policies? Office 365 labels are starting to get quite prolific across the stack now and I\u2019m starting to see better uses for them over SharePoint Retention policies. If you\u2019re not familiar with Office 365 labels, my MVP colleague Joanne Klein has a great blog post from last year that &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[139],"tags":[173,56,115,198],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Configuring default Office 365 Labels using PowerShell - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configuring default Office 365 Labels using PowerShell - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"Office 365 Labels over Information Management Policies? Office 365 labels are starting to get quite prolific across the stack now and I\u2019m starting to see better uses for them over SharePoint Retention policies. If you\u2019re not familiar with Office 365 labels, my MVP colleague Joanne Klein has a great blog post from last year that &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-16T20:20:30+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/\",\"name\":\"Configuring default Office 365 Labels using PowerShell - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png\",\"datePublished\":\"2018-05-16T20:20:30+00:00\",\"dateModified\":\"2018-05-16T20:20:30+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/#primaryimage\",\"url\":\"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png\",\"width\":759,\"height\":234},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Configuring default Office 365 Labels using PowerShell - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Configuring default Office 365 Labels using PowerShell - Blog of an overweight SharePoint addict","og_description":"Office 365 Labels over Information Management Policies? Office 365 labels are starting to get quite prolific across the stack now and I\u2019m starting to see better uses for them over SharePoint Retention policies. If you\u2019re not familiar with Office 365 labels, my MVP colleague Joanne Klein has a great blog post from last year that &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2018-05-16T20:20:30+00:00","og_image":[{"url":"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png"}],"author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/","name":"Configuring default Office 365 Labels using PowerShell - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/#primaryimage"},"image":{"@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png","datePublished":"2018-05-16T20:20:30+00:00","dateModified":"2018-05-16T20:20:30+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2018\/05\/configuring-default-office-365-labels-using-powershell\/#primaryimage","url":"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png","contentUrl":"http:\/\/www.myfatblog.co.uk\/wp-content\/uploads\/2018\/05\/SNAGHTML51f9590_thumb.png","width":759,"height":234},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1393"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1393"}],"version-history":[{"count":2,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1393\/revisions"}],"predecessor-version":[{"id":1396,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1393\/revisions\/1396"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}