Set a default Label in a SharePoint Online Document Library

Office 365 Labels are a feature of Office 365 that allows you to manually or automatically label content across all of Office 365 including SharePoint online. Check out my other blog post for some more background:

https://colinjwood.wordpress.com/2018/07/19/using-office-365-labels-with-sharepoint-search/

One of the really useful features of Labels and SharePoint is that you can set a default label on a per document library basis. What this means is that all content going into your document library will be set with a default label and making the process of applying a label to content less onerous on the user.

To do this, go into your document library settings and click on ‘Apply label to items in this list or library’:

defaultlibrarysetting

Then you can select the default label from all the labels enabled on your site:

labeloptions

Now when a user saves content to the document library it will default to this label:

defaultlabelapplied

It is also possible to set the default label for a document library programmatically which is really useful especially if you are provisioning a lot of document libraries using code or PowerShell.

SPPolicyStoreProxy.SetListComplianceTag

SetListComplianceTag(ClientRuntimeContext context, string listUrl, string complianceTagValue, bool blockDelete, bool blockEdit, bool syncToItems);

SPPolicyStoreProxy

Unfortunately I can’t find much documentation on this method at this stage as it only recently has been added to SharePoint Online CSOM.

Advertisements

Using Office 365 Labels with SharePoint Search

What are Office 365 Labels?

Label the right content with the right actions against it. Across your organization, you probably have different types of content that require different actions taken on them in order to comply with industry regulations and internal policies. Labels allow users to classify data within their organisation for governance and enforce retention based on the classification of content in Office 365.

Labels are configured in your Office 365 tenant under the Security and Compliance Administration Center:Office365center.png

createlabel

In short, you create a Label and Publish it as part of a policy that can target specific areas of Office 365 or across the entire Office 365. Labels can be set to automatically be applied to content that match either search queries or match specific information types such as credit card numbers or passport numbers, identified as personal information, or they can be manually applied by users.

Labels can have retention settings specified and any content that has the label applied can be set to being declared as a record:

retentionsettings

Searching for SharePoint content with specific Labels

As there will be lots and lots of content in SharePoint online with different labels applied, it becomes important that users can search and identify different content:

  • Records Managers need to identify content with specific retention policies applied across all of SharePoint
  • Project Management officers need to identify all project content with specific labels and related to specific projects that match specific contract obligations
  • Ensure sensitive and other content related to an individual is identified and removed from SharePoint to comply with GDPR policies

If you have been granted the appropriate permissions in SharePoint and the Office 365 Security and Compliance Center you can perform searches for specific labels across all of Office 365 (Exchange, SharePoint, Teams, OneDrive):

ContentSearchSandC

Looking at how you search for specific labels it seems the search is against a ComplianceTag property:

searchsandc

Based on this information, it would seem that there is a Managed Search Property called ‘ComplianceTag’. Looking at the SharePoint online search schema confirms this and because it is searchable it can be used by any search queries against SharePoint:

searchschema

This opens up the potential that content can be searched for by specific labels in SharePoint online by any users. The example below shows a simple search across SharePoint online for content matching two different labels:

searchlabels

ComplianceTag:”Project Documentation” OR ComplianceTag:”Marketing Material”

As mentioned previously this content could have actions associated with it such as a disposition review as it is tagged with a specific label. As there could be numerous SharePoint site collections, using search to bring this content together that match specific labels is really powerful. You can then use the power of search to preview content or open it up or edit metadata.

Combining an Office 365 label search with other search parameters

As labels are exposed as a normal Managed Property in search we can use it like any other property in a Keyword Query Lanaguage (KQL) query. Taking the example above I can extend it further by checking for all content matching labels and where the author is myself:

ComplianceTag:”Project Documentation” OR ComplianceTag:”Marketing Material” AND Author:”Colin Wood”

SearchUser

So you can now build up simple or more advanced queries that returns content matching specific labels in addition to other search parameters which gives users even more powerful options in terms of returning content against specific criteria. It maybe that we need to identify sensitive content relating to specific projects or users for example.

OnePlaceLive and Office 365 Labels

OnePlaceLive is one our products here at OnePlace Solutions. It allows you to reduce the complexity of SharePoint by delivering SharePoint locations and content to different groups of users inside their favorite applications such as Outlook: https://www.oneplacesolutions.com/solution-profiles.html

We deliver these using ‘Solution Profiles’ that in essence are a search query against SharePoint that can be defined once and dynamically executed by users. They can be targeted to different groups of users such as users of a Legal Matter Management System, Project Management System or Records Managers.

Now that we have identified we can find content matching specific labels with a SharePoint search we can create solution profiles that can search for content matching specific labels and/or combined with any other search properties you want to search on. We can then deliver this content to users inside Outlook for example, where they spend most of their time day in day out.

solutionprofilecreation

We create the solution profile above where we define the search query. In the example above I am creating a solution profile that could be used by records managers. It is looking for content with specific labels and because I know that any content with these labels are declared as records, it will identify all records across all of SharePoint online. I then publish this profile and it automatically appears inside Outlook, where the Records Manager can click on it and execute the query and view all records in SharePoint online inside Outlook:

allrecords

I can then add specific profiles for say, Marketing Records to just show Marketing Records.

marketingrecords

These are fairly simple examples but you get the idea, the queries can be as simple or as complex as you want or need it to be and can target different groups of users.

So hopefully what you can now see is that you can use labels in Office 365 as part of your SharePoint search queries. What is really powerful is the ability to use labels in combination with other search properties to identify content that is particularly sensitive or has certain compliance actions associated with it. This is really beneficial from a GDPR perspective to identify personal GDPR data (content that may be labelled with specific GDPR related Office 365 labels and specific to a user) and really useful for Records Managers and many other business applications. Once content is labelled, it is important that this content can be found and identified so actions can be performed on it.

Provision multiple SharePoint Online site collections with PnP PowerShell

This blog post follows on from my previous blog post on basic SharePoint site collection provisioning in Office 365: https://colinjwood.wordpress.com/2017/12/14/create-a-sharepoint-site-collection-in-an-office-365-tenant-with-pnp-powershell/

In this post I will go through how you can provision multiple site collections in an Office 365 tenant using a csv file which specifies configuration information about each site collection:

  • Url
  • Site Owner
  • Template
  • Timezone
  • Title

The source code for this post is in my GitHub repo at: https://github.com/colinjwood/CodeCobra/tree/master/CSVProvisioning

The script is here: https://github.com/colinjwood/CodeCobra/blob/master/CSVProvisioning/createSiteCollectionsFromCSV.ps1

I have included an example csv file in the repo that the script uses. It needs to be located in ‘C:\\temp’ on local machine running the script. This step could also be automated so that the csv file is downloaded from GitHub to the temp folder on the local machine, then used by the script for site collection provisioning. I use this technique in one of my other GitHub repos here at OnePlace Solutions to provision Site Columns in SharePoint. The provisioning xml is downloaded then used by the PowerShell script : https://github.com/OnePlaceSolutions/EmailColumnsPnP/blob/master/installEmailColumns.ps1

image

To run the SharePoint site collection provisioning script perform the following:

  • Create your csv file with all the site collection configuration information based on the example csv provided and locate it in c:\temp on your machine running the PowerShell script.
  • Run Windows PowerShell and copy and paste the following command at the command prompt:
Invoke-Expression (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/colinjwood/CodeCobra/master/CSVProvisioning/createSiteCollectionsFromCSV.ps1')
  • Enter the url of your SharePoint online tenant:

image

  • The site collections will be provisioned in your tenant based on the configurations provided in the csv file. To confirm progress check the Site list in the SharePoint Admin are of your tenant.

This gives you an example of how to configure all or some of the site collections in your Office 365 tenant and create them with one script. This could form the basis of any scripts you write to perform site collection provisioning.

Create a SharePoint site collection in an Office 365 Tenant with PnP PowerShell

Before getting started with PnP PowerShell you need to ensure you have the pre-requisites enabled on your machine. I have detailed the pre-reqs here in previous GitHub repos I have done for our products here at OnePlace Solutions and as we will be targeting SharePoint Online we need to ensure we install the PnP cmdlets for SharePoint online only: https://github.com/OnePlaceSolutions/EmailColumnsPnP

This blog post details how you can create a site collection in an Office 365 tenant using PowerShell.

I have added a PowerShell script to my GitHub repo https://github.com/colinjwood/CodeCobra which I will go through in more detail.

The script that provisions the site collection is here: https://github.com/colinjwood/CodeCobra/blob/master/createSiteCollection.ps1

This script prompts for key information to provision the site collection with. The site template is based on the standard ‘Team Site’ template in SharePoint, however this information could be prompted for and added dynamically to your script.

To execute this script and provision a site collection do the following:

  • Start PowerShell on your machine
  • Copy and paste the following command into your PowerShell command window:
    Invoke-Expression (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/colinjwood/CodeCobra/master/createSiteCollection.ps1')
    
  • Enter your SharePoint tenant url and you will be prompted to login, use your email address :

SNAGHTML8f385c2

  • Enter the url of your new site collection to be provisioned:
  • SNAGHTML9009eba

    • Enter the site owner of your new site collection by typing in the email address
    • Enter the timezone, I type 76 as I live in Sydney
    • The new site collection will now be provisioned in Office 365. To confirm and check progress go into the SharePoint Admin area of your tenant and go to the list of site collections and you will see your new site collection:

    SNAGHTML961a9ce

    The command used in this script is:

    New-PnPTenantSite

    Here is the official documentation on this cmdlet: https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/New-PnPTenantSite.md

    I extend the provisioning process in my other blog post where administrators can create a csv file defining multiple site collections, the template they are based on, the urls, site owners, regional settings etc. and provision them all with PowerShell in an Office 365 tenant:

    https://colinjwood.wordpress.com/2017/12/14/provision-multiple-sharepoint-site-collections-with-pnp-powershell/

    Save emails and documents to SharePoint in the background

    Recently, myself and the dev team at OnePlace Solutions completed a challenging yet very rewarding project.

    We are all about user productivity and SharePoint adoption and the results of this project are significant gains in both of these areas.

    Please check out my blog on our company website which details the new background save of emails and documents to SharePoint:

    https://www.oneplacesolutions.com/news/increase-user-productivity-by-saving-documents-and-emails-to-sharepoint-while-working-on-other-tasks.html

    Deploy SharePoint Site Columns with One PowerShell command

    Recently, I had to come up with a new way to deploy our email site columns for our OnePlaceMail product as the old way (sandboxed solutions) were no longer supported.

    I had to make it simple for users and come up with a way that would allow me to easily modify/add site columns in the future.

    I decided to use the SharePoint PnP PowerShell Cmdlets and GitHub to host the solution so users could simply run 1 PowerShell command, enter a site collection url and the site columns would be deployed to their site collection.

    The process is as follows:

    • Execute PowerShell command to run PowerShell script (ps1) hosted in GitHub.
    • User is prompted for the Site Collection Url, enter url and hit return
    • Provisioning Xml template which details all the Site Columns settings is downloaded to the user’s temp folder on their machine.
    • PnP provisioning command is executed to apply provisioning template to the Site Collection and therefore provisioning the Site Columns.

    If in the future if I need to remove/add/modify any Site Columns I simply edit the provisioning xml:

    provisioningxml

    Below details the full PowerShell script and the GitHub repo can be found here: https://github.com/OnePlaceSolutions/EmailColumnsPnP

    <#
            This script prompts you to install the SharePoint PnP commands. Hit enter for SharePoint Online,
            6 for SharePoint 2016,3 for SharePoint 2013
            The script then prompts for the site collectiuon url you wish to install the Email Columns to
            and then applies the email columns template to this site collection        
    #>
    
    try {    
        Set-ExecutionPolicy Bypass -Scope Process 
        #Prompt for SharePoint Url     
        $SharePointUrl = Read-Host -Prompt 'Enter your SharePoint Site Collection Url to install OnePlace Solutions Email Columns to'
        Connect-pnpOnline -url $SharePointUrl
        #Download xml provisioning template
        $WebClient = New-Object System.Net.WebClient   
        $Url = "https://raw.githubusercontent.com/OnePlaceSolutions/EmailColumnsPnP/master/email-columns.xml"    
        $Path = "$env:temp\email-columns.xml"
    
        Write-Host "Downloading provisioning xml template:" $Path -ForegroundColor Green 
        $WebClient.DownloadFile( $Url, $Path )   
        #Apply xml provisioning template to SharePoint
        Write-Host "Applying email columns template to SharePoint:" $SharePointUrl -ForegroundColor Green 
        Apply-PnPProvisioningTemplate -path $Path
       
    }
    catch {
        Write-Host $error[0].Message
    }
    

    Open pdfs in Office 2013 Web Apps

    Great to see that Office web apps 2013 support opening pdfs: http://blogs.office.com/b/officewebapps/archive/2013/07/03/pdfs-in-the-word-web-app.aspx

    Pdfs have always been a special case to deal with in SharePoint, setting their custom icon for display in libraries and indexing them for search etc. It’s good to see Microsoft acknowledging them and now allowing you to open them up in in the Word Web app.

    Here is a good technical article on configuring it on-premise (Office 365 should have it all pre-configured for you):

    http://melcher.it/2013/05/install-office-web-apps-2013-for-sharepoint-2013-with-pdf-preview/