Accessing Compliance Center using PowerShell in Office 365

Guest Post by Isha Kapoor

Compliance Center is a tool that was recently added to Office 365 admin panel to facilitate searching mailboxes, SharePoint Online Content, and OneDrive for Business locations.

With Compliance Center, an administrator can setup a Compliance Search which provides an option to Search SharePoint Content across all or specific SharePoint Online sites in Office 365. The UI designed for Compliance center is user-friendly and is easy to use but an option to run Compliance Searches using PowerShell is also available.

In the following blog post, we will look at the PowerShell cmdlets that can be used for accessing Compliance Center and setting up a Compliance Search for SharePoint Online sites.

To begin with, a global administrator needs to first Connect to Office 365 using PowerShell. For details, please refer to Connect to Office 365 using PowerShell

Next, the following Commands should be ran to Connect to the Compliance Center using PowerShell.

1. In the PowerShell Window, run the following command

$UserCredential = Get-Credential

In the Credential Request dialog box, type your Office 365 user name and password, and then click OK.

2. Run the following command.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic –AllowRedirection

3. Finally, run the following command to import the session

Import-PSSession $Session

This should connect your PowerShell to Compliance Center in Office 365.

4. Next, for an administrator to have access to the Compliance Center, specific permissions are needed. The basic permissions that are required are:

a) An Administrator either needs to be an Office 365 global admin or a member of one or more Compliance Center role groups.

b) For an Administrator to have access to the Compliance search page to perform compliance searches, they have to be a member of Compliance Administrator and eDiscovery Manager role group in the Compliance Center.

Let’s look at commands to add a user to Compliance Administrator and eDiscovery Manager role group in the Compliance Center.

To add a user to ComplianceAdministrator role, use the Add-RoleGroupMember cmdlet as following.

Add-RoleGroupMember "ComplianceAdministrator" -Member "Isha Kapoor"

Repeat the command for eDiscoveryManager role.

Add-RoleGroupMember "eDiscoveryManager" -Member "Isha Kapoor"

Note: You must be logged in as a global administrator to perform the above Operations.

5. Now, once the permissions are all setup, the next step is to configure the Compliance Search. To create a new Compliance Search, Compliance user can use the New-ComplianceSearch cmdlet as following.

New-ComplianceSearch -Name "SP Compliance Search" -SharePointLocation "https://spsite.sharepoint.com" -ContentMatchQuery createdby:'"Isha Kapoor"'

The above command creates a Compliance Search entry with the name "SP Compliance Search", as shown in the screenshot below.

clip_image002

Notice that we have also used 'ContentMatchQuery' parameter which lets you specify the query that the search results can be filtered upon.

After you have created a Compliance Search, to edit the Keyword Query, you can use the Set-ComplianceSearch cmdlet to edit the ContentMatchQuery parameter.

Example: Set-ComplianceSearch -Identity "SP Compliance Search" -ContentMatchQuery created:'"08/19/2015" '

For more examples see: Keyword queries for Compliance Search

You can also verify the Compliance Search creation by running the following.

Get-ComplianceSearch | Format-Table Name, Status.

6. Once you have the Compliance Search Created, the next step is to start the Search. To start the Search, run the following Command.

Start-ComplianceSearch -Identity "SP Compliance Search"

7. Following the Start, a new Compliance Search Action needs to be created to track the status of the Search activity. Run the following to create a new Action using the New-ComplianceSearchAction cmdlet.

New-ComplianceSearchAction -SearchName "SP Compliance Search" -Preview

clip_image004

Tip: The time it takes run the Action depends upon the number of results being returned. So give it some time before you try to download the results.

8. Finally, run the Get-ComplianceSearchAction cmdlet to verify the status of the query and to download the results.

To confirm the status of the Action run the following:

Get-ComplianceSearchAction -Identity "SP Compliance Search_Preview" | Select Status

clip_image006

To download the results as a csv file run the following:

Get-ComplianceSearchAction -Identity "SP Compliance Search_Preview" | Select Results | Export-Csv c:\results.csv

For instructions on how to configure Compliance search through UI, see my blog post here

clip_image008

Isha Kapoor is a SharePoint Geek, a blogger, author, Trainer and a SharePoint Server MVP from Toronto, Canada. She is a founder and Primary Contributor of popular website www.LearningSharepoint.com. Follow her on twitter @LearningSP for latest SharePoint updates more.