Enable Microsoft 365 SafeLinks Using PowerShell

In this blog post, we are going to learn how to enable Microsoft 365 SafeLinks using PowerShell.


Before we get into the configuration, let first understand what SafeLinks is. Microsoft 365 SafeLinks are a licenced service that is part of Microsft Defender for Office 365.

SafeLinks scan every URL that comes with any inbound email and test that it doesn’t contain malicious code, sites or phishing attacks. SafeLink will test the URL by clicking on it and test it before releasing the email to your users.

To enable SafeLinks you will need Microsoft Defender for Office 365 plan 1 or plan 2. If you are on an E5 licences you also get SafeLinks.

Enable SafeLinks

To enable SafeLinks in Microsoft 365 using PowerShell, we need to use the Exchange Online PowerShell module.

For SafeLinks, we need the Exchange Online V2 PowerShell module, which you can install using the following command (Windows).

Install-Module -Name ExchangeOnlineManagement

To connect to Exchange Online using PowerShell after installing the module using the following command:


Once connect, I will use the following command to create a SafeLinks policy name Safe-Links. The name is important becuase we will use in the next command to create the actual SafeLinks rule.

New-SafeLinksPolicy -Name "Safe-Links" -IsEnabled $true -TrackClicks $true -DoNotAllowClickThrough $true -DeliverMessageAfterScan $true -DoNotTrackUserClicks $false -EnableForInternalSenders $true -scanurls $true 

After creating the policy I will create the rule that will apply the policy. below I’m calling the rule NTWEEKLY and I am using the policy I created above which is called Safe-Links. I’m also applying the rule to two domains.

New-SafeLinksRule -Name "NTWEEKLY" -SafeLinksPolicy "Safe-Links"  -RecipientDomainIs "ntweekly.com", "deploycontainers.com"