PowerShell: Connect to the Security & Compliance Center

I had to recently do some eDiscovery work in the Security and Compliance Center (I’ll post about that next, there was some cool PowerShell in there too 🙂 ), and as I often do, I turn to PowerShell to automate the process – or at least make it easier for me to do more things without the limitations of having to click around in the GUI.

Of course, first things first is getting connected – Microsoft has made the connectivity easy using the Exchange Online Modern Auth PowerShell Module, which allows you to connect to both an Exchange Online admin session, as well as to the Security & Compliance Center using Connect-IPPSSession.

Mind you, if you’ve seen any of my stuff before, you know I’m going to want to find a way to connect using PowerShell ISE – because that’s just how I roll!

As before, I was able to update my Exchange Online connection script to target the protection.outlook.com URI instead of the Exchange Online admin URI, like so:

#Connect to the Security & Compliance Center

Write-Host “Connecting to the Security and Compliance Center” -ForegroundColor Green

$UPN = Read-Host “Enter the UPN of the user you want to connect with”

Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+“Apps2.0”) -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch “_none_”}|select -First 1)

$EXOSession = New-ExoPSSession -ConnectionUri https://ps.compliance.protection.outlook.com/PowerShell-LiveId-UserPrincipalName $UPN

Import-PSSession $EXOSession

You’ll notice we’re using the same module we use to connect to Exchange Online using MFA – I’ve simply updated the connection string to go to the Security & Compliance Center instead of Exchange Online. Apart from that, it’s more or less the same. As before, I still pass along a connection to Azure AD in case I want to be able to manage those attributes at the same time. You can also modify this to connect to the ExO (Exchange Online) shell at the same time if you like, or just keep them separate – up to you.

I’ve also updated the script to check for an existing connection to the Security & Compliance Center, as I like to be able to run my scripts multiple times without re-authenticating – head on over to GitHub and grab yourself a copy if you’d like.

Thanks for reading!


2 thoughts on “PowerShell: Connect to the Security & Compliance Center

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.