<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Exchange Online on Alfred van Ster</title><link>https://avanster.tech/tags/exchange-online/</link><description>Recent content in Exchange Online on Alfred van Ster</description><generator>Hugo -- 0.161.1</generator><language>en-us</language><lastBuildDate>Sun, 03 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://avanster.tech/tags/exchange-online/index.xml" rel="self" type="application/rss+xml"/><item><title>M365 Security: Unauthorized Mailbox Forwarding Auditor</title><link>https://avanster.tech/library/script-exchange-forwarding-auditor/</link><pubDate>Sun, 03 May 2026 00:00:00 +0000</pubDate><guid>https://avanster.tech/library/script-exchange-forwarding-auditor/</guid><description>&lt;ol&gt;
&lt;li&gt;The Workflow&lt;/li&gt;
&lt;li&gt;The Implementation&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A classic BEC tactic involves configuring an inbox rule to forward emails to an external address. This script audits an entire Exchange Online tenant for any mailboxes with active forwarding rules to external domains.&lt;/p&gt;
&lt;h3 id="1-the-workflow"&gt;1. The Workflow&lt;/h3&gt;
&lt;p&gt;The script performs the following steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Connection:&lt;/strong&gt; Authenticates to Exchange Online via module parameters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auditing:&lt;/strong&gt; Iterates through all user mailboxes checking forwarding properties.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Evaluation:&lt;/strong&gt; Compares the forwarding destination against the tenant&amp;rsquo;s accepted domains.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Alerting:&lt;/strong&gt; Outputs a high-priority warning if external exfiltration is detected.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="2-the-implementation"&gt;2. The Implementation&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-powershell" data-lang="powershell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Connect-ExchangeOnline -ShowBanner:$false
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$AcceptedDomains = (Get-AcceptedDomain).Name
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;foreach&lt;/span&gt; ($Mailbox &lt;span style="color:#66d9ef"&gt;in&lt;/span&gt; (Get-Mailbox -ResultSize Unlimited)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; ($Mailbox.ForwardingSmtpAddress) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $ForwardDestination = $Mailbox.ForwardingSmtpAddress.Replace(&lt;span style="color:#e6db74"&gt;&amp;#34;smtp:&amp;#34;&lt;/span&gt;,&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; ($ForwardDestination &lt;span style="color:#f92672"&gt;-notmatch&lt;/span&gt; ($AcceptedDomains -join &lt;span style="color:#e6db74"&gt;&amp;#34;|&amp;#34;&lt;/span&gt;)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Write-Host &lt;span style="color:#e6db74"&gt;&amp;#34;⚠️ EXTERNAL FORWARD: &lt;/span&gt;$($Mailbox.UserPrincipalName)&lt;span style="color:#e6db74"&gt; -&amp;gt; &lt;/span&gt;$ForwardDestination&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; -ForegroundColor Red
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>