Protecting your organization from phishing attacks and malicious links is crucial, and Exchange Online's Safe Links feature plays a key role in this defense. However, it's important to ensure that Safe Links policies are correctly configured and applied across all necessary domains.
This article provides a step-by-step guide on how to use PowerShell to audit Safe Links policies in Exchange Online. The script checks if these policies are applied to all domains, helping administrators maintain consistent protection across their entire organization.
Here is the script:
# Connect to Exchange OnlineConnect-ExchangeOnline# Get all Safe Links policies$safeLinksPolicies = Get-SafeLinksPolicy# Function to check if Safe Links policies are applied to all domainsfunction Check-SafeLinksPolicy {param ([string]$policyName)# Get the details of the specific Safe Links policy$policy = Get-SafeLinksPolicy -Identity $policyName# Check if the policy is applied to all domains$appliedToAllDomains = $trueif ($policy.DomainsIncluded.Count -eq 0 -and $policy.DomainsExcluded.Count -eq 0) {$appliedToAllDomains = $true} else {$appliedToAllDomains = $false}return $appliedToAllDomains}# Prepare an array to hold the policy check results$policyCheckResults = @()foreach ($policy in $safeLinksPolicies) {$policyName = $policy.Name$isAppliedToAllDomains = Check-SafeLinksPolicy -policyName $policyName$policyCheckResults += [PSCustomObject]@{PolicyName = $policyNameAppliedToAllDomains = $isAppliedToAllDomains}}# Display the policy check results$policyCheckResults | Format-Table -AutoSize# Optionally export to CSV$policyCheckResults | Export-Csv -Path "SafeLinksPolicyCheckResults.csv" -NoTypeInformationWrite-Output "Safe Links policy check results exported to SafeLinksPolicyCheckResults.csv"# Disconnect from Exchange OnlineDisconnect-ExchangeOnline -Confirm:$false
Help Center