Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@
[OutputType([bool])]
param()


if ( ( Get-MtLicenseInformation DefenderXDR ) -ne "DefenderXDR" ) {
# Add-MtTestResultDetail -SkippedBecause NotLicensedDefenderXDR
# return $null
if (-not (Test-MtConnection ExchangeOnline)) {
Add-MtTestResultDetail -SkippedBecause NotConnectedExchange
return $null
} else {
$checkType = "ExchangeOnline"
}
if (Get-MtLicenseInformation -Product Mdo) {
$checkType = "DefenderForOffice365P2"
} elseif (-not (Test-MtConnection ExchangeOnline)) {
Add-MtTestResultDetail -SkippedBecause NotConnectedExchange
return $null
} else {
$checkType = "DefenderXDR"
$checkType = "ExchangeOnline"
}

$return = $true
if ($checkType -eq "DefenderXDR") {
if ($checkType -eq "DefenderForOffice365P2") {
Write-Verbose "Checking if mailboxes send outbound mails using the .onmicrosoft.com domain..."
try {
$outboundTreshold = 100
Expand Down Expand Up @@ -66,16 +61,25 @@
} elseif ($checkType -eq "ExchangeOnline") {
Write-Verbose "Checking if mailboxes use the .onmicrosoft.com domain as primary SMTP address..."
try {
$allMbx = Get-Mailbox | Where-Object { $_.PrimarySmtpAddress -like "*@*.onmicrosoft.com" }
if (($allMbx | Measure-Object).Count -eq 0) {
$mbxes = Get-Mailbox -ResultSize Unlimited -Filter "RecipientTypeDetails -ne 'DiscoveryMailbox'" | Where-Object { $_.PrimarySmtpAddress -like "*@*.onmicrosoft.com" }
if (($mbxes | Measure-Object).Count -eq 0) {
$result = "Well done. No mailbox uses the .onmicrosoft.com domain as primary SMTP address."
Add-MtTestResultDetail -Result $result
} else {
$mgUsers = @()
foreach ($mbx in $allMbx) {
$mgUsers += Invoke-MtGraphRequest -RelativeUri "users" -UniqueId $mbx.ExternalDirectoryObjectId
$mailboxWithoutExternalDirectoryObjectIdDisplayNames = $mbxes | `
Where-Object { -not $_.ExternalDirectoryObjectId } | `
Select-Object -ExpandProperty DisplayName
[array]$mgUsers = foreach ($mbx in $mbxes) {
if ($mbx.ExternalDirectoryObjectId) {
Invoke-MtGraphRequest -RelativeUri "users" -UniqueId $mbx.ExternalDirectoryObjectId
}
}
$result = "Your tenant has $(($mbxes | Measure-Object).Count) mailboxes using the .onmicrosoft.com domain as primary SMTP address:`n`n%TestResult%"
if (($mailboxWithoutExternalDirectoryObjectIdDisplayNames | Measure-Object).Count -ge 1) {
$mailboxWithoutExternalDirectoryObjectIdDisplayNamesResult = $mailboxWithoutExternalDirectoryObjectIdDisplayNames -join "`n+ "
$result += "`n`nThe following mailboxes have no ExternalDirectoryObjectId and could not be looked up in Microsoft Graph:`n+ $mailboxWithoutExternalDirectoryObjectIdDisplayNamesResult"
}
$result = "Your tenant has $(($allMbx | Measure-Object).Count) mailboxes using the .onmicrosoft.com domain as primary SMTP address:`n`n%TestResult%"
$return = $false
Add-MtTestResultDetail -Result $result -GraphObjects $mgUsers -GraphObjectType Users
}
Expand Down
Loading