Created
July 14, 2019 15:04
-
-
Save alexverboon/7104e6fa24da8449c620398847e92e12 to your computer and use it in GitHub Desktop.
Verify-MSCoreUTransportWhitelists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Verify-MSCoreUTransportWhitelists | |
{ | |
<# | |
.Synopsis | |
Verify-MSCoreUTransportWhitelists | |
.DESCRIPTION | |
The Verify-MSCoreUTransportWhitelists cmdlet lists whitelisted domains if present | |
Secure Score Reference: Do not use transport white lists | |
#> | |
[CmdletBinding()] | |
Param | |
( | |
[System.Management.Automation.PSCredential]$userCredential | |
) | |
Begin | |
{ | |
Try{ | |
#This gets us connected to an Exchange remote powershell service | |
$ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $userCredential -Authentication Basic -AllowRedirection | |
Import-PSSession $ExoSession | |
} | |
Catch{ | |
write-error "Error loading exchange online module" | |
Remove-PSSession $ExoSession | |
exit | |
} | |
} | |
Process | |
{ | |
$whitelisttransportrules = Get-TransportRule | Where-Object {$_.Conditions -like "Microsoft.Exchange.MessagingPolicies.Rules.Tasks.SenderDomainIsPredicate" -and $_.Actions -like "Microsoft.Exchange.MessagingPolicies.Rules.Tasks.StopRuleProcessingAction"} | |
$result = @() | |
ForEach ($rule in $whitelisttransportrules) | |
{ | |
$object = [PSCUSTOMOBJECT] @{ | |
Name = $rule.Name | |
State = $rule.State | |
Description = $rule.Description | |
SenderDomainList = $rule.SenderDomainIs | |
StopRuleProcessing = $rule.StopRuleProcessing | |
Conditions = $rule.Conditions | |
Actions = $rule.Actions | |
} | |
$result = $result + $object | |
} | |
$output = [pscustomobject]@{ | |
SecureScoreReference = "Do not use transport white lists" | |
RuleCount = $result.Count | |
Data = $result | |
} | |
} | |
End | |
{ | |
Remove-PSSession $ExoSession | |
$output | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment