---
title: Sendmarc Microsoft 365 Set PostMaster PowerShell Script
description: PowerShell Script to set the PostMaster address in MS365
---

[Skip to content](https://help.sendmarc.com/sendmarc-microsoft-365-set-postmaster-script#main-content)

English

Show submenu for translations

[Log a New Ticket](https://help.sendmarc.com/kb-tickets/new?hsLang=en)

[![Sendmarc-Logo-Dark.png\]](https://help.sendmarc.com/hs-fs/hubfs/Sendmarc-Logo-Dark.png?height=24&name=Sendmarc-Logo-Dark.png)](https://help.sendmarc.com?hsLang=en)

- [Home](https://help.sendmarc.com/)
- [View Tickets](https://connect.sendmarc.com/tickets-view)
- [Provide Product Feedback](https://sendmarc.notion.site/29c84b281bbf80868e2fc569ede1b8be?pvs=105)

Open main navigation

Close main navigation

- [Home](https://help.sendmarc.com/)
- [View Tickets](https://connect.sendmarc.com/tickets-view)
- [Provide Product Feedback](https://sendmarc.notion.site/29c84b281bbf80868e2fc569ede1b8be?pvs=105)
- English
  
  Show submenu for translations
- [Log a New Ticket](https://help.sendmarc.com/kb-tickets/new)

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Sendmarc Help Center | DMARC & Email Security Support](https://help.sendmarc.com/?hsLang=en)
2. [Other](https://help.sendmarc.com/other?hsLang=en)
3. [Scripts](https://help.sendmarc.com/other?hsLang=en#scripts)

# Sendmarc Microsoft 365 Set PostMaster PowerShell Script

## PowerShell Script to set the PostMaster address in MS365

### !Important!

Sendmarc provides no support for PowerShell scripts and these are executed at your own risk. 

Sendmarc takes no responsibility for any issues that this script might cause.

Please read through the code before executing the script

 Please copy the contents of this script below into a TXT file and rename the file as "Sendmarc Sendmarc Microsoft 365 PostMaster Enabler.ps1"

Should the script successfully execute, a log file will be created at C:\\Sendmarc\\nameofscript.txt

Please review this article on how to execute a PowerShell Script:

[How To Run PowerShell Scripts](https://help.sendmarc.com/how-to-run-powershell-scripts?hsLang=en)

### Script Objective

The objective of this script is to allow you to set the PostMaster address in MS365

The script will automatically prompt you for input upon execution to set a PostMaster address.

The script will query you to login into MS365, please ensure the account you are logging in with has access to security.microsoft.com

### Script Contents

```
#SENDMARC POSTMASTER ENABLER#Author: Brian Goosen - brian@sendmarc.com#Usage of this Script is at your own risk.#COPYRIGHT SENDMARC#V2.0#Changelog#Added Functions to drive application flow.$hostGui = $Host.UI.RawUI$HostGui.WindowTitle = "Sendmarc MS365 PostMaster Enabler V1.0"$HostGui.ForegroundColor = "White"# Check if the script is running with administrative privileges$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)# If not running as admin, relaunch the script with elevated permissionsif (-not $isAdmin) {    Write-Host "This script requires administrative privileges. Please run the script as an administrator." -ForegroundColor Cyan        # Relaunch the script with elevated permissions    Start-Process powershell.exe -Verb RunAs -ArgumentList "-File $($MyInvocation.MyCommand.Path)"}# Generate a timestamp for the log file name$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"# Create a log file path$logFilePath = "C:\Sendmarc\Sendmarc_PostMaster_Enable_LogFile_$timestamp.txt"# Start loggingStart-Transcript -Path $logFilePathWrite-Host "==================================================" -ForegroundColor GreenWrite-Host "Sendmarc MS365 PostMaster Enabler" -ForegroundColor GreenWrite-Host "Author: Brian Goosen" -ForegroundColor GreenWrite-Host "Email: Brian@sendmarc.com" -ForegroundColor GreenWrite-Host "COPYRIGHT SENDMARC" -ForegroundColor GreenWrite-Host "==================================================" -ForegroundColor Greenfunction LaunchApplication {    #Confirm Application Launch    $title = 'Configure MS365 PostMaster'    $question = 'Do you want to continue?'    $choices = '&Yes', '&No'    $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)    if ($decision -eq 0) {        ConnecttoMS365        GetCurrentPostmaster        SetPostMaster    }    else {        Write-Host "Script Aborted" -ForegroundColor Red        Exit    }}function ConnecttoMS365 {    Write-Host "Checking if ExchangeOnlineManagement is installed" -ForegroundColor Cyan    if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {        Write-Host "Installing ExchangeOnlineManagement Powershell Module" -ForegroundColor Cyan        Install-Module -Name ExchangeOnlineManagement -Force -Scope CurrentUser    }    else {        Write-Host "ExchangeOnlineManagement is installed" -ForegroundColor Cyan    }    Write-Host "Importing ExchangeOnlineManagment" -ForegroundColor Cyan    Import-Module ExchangeOnlineManagement    Write-Host "Connecting to MS365" -ForegroundColor Cyan    Write-Host "Please Log into MS365" -ForegroundColor Cyan    Connect-ExchangeOnline    Write-Host "Connected to MS365" -ForegroundColor Cyan}function GetCurrentPostmaster {    Write-Host "Getting Current PostMaster Address" -ForegroundColor Cyan    Write-Host "Curernt PostMaster Address is:" -ForegroundColor Cyan    Get-TransportConfig | Format-List ExternalPostmasterAddress}function SetPostMaster {    #Confirm Postmaster Change    $title = 'Change Postmaster Address?'    $question = 'Do you want to continue?'    $choices = '&Yes', '&No'    $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)    if ($decision -eq 0) {        $postMasterAddress = Read-Host "Enter New Postmaster Address (postmaster@domain.com)"        Set-TransportConfig -ExternalPostmasterAddress $postMasterAddress        Write-Host "Getting Current PostMaster Address" -ForegroundColor Cyan        Write-Host "New PostMaster Address is:"        Get-TransportConfig | Format-List ExternalPostmasterAddress    }    else {        Write-Host "Script Aborted" -ForegroundColor Red        return    }    }#Launch ApplicationLaunchApplicationWrite-Host ""Write-Host "==================================================" -ForegroundColor CyanWrite-Host "Thank you for choosing Sendmarc!" -ForegroundColor CyanWrite-Host "==================================================" -ForegroundColor Cyan# Stop loggingStop-Transcript# Display the path of the log fileWrite-Host "Log file created: $logFilePath"Write-Host "Press Enter to Close This Program" -ForegroundColor CyanRead-Host "..."
```

### Need Help?

Sendmarc does not provide any support for PowerShell scripts and are run at your own risk.

- [Portal Guides](https://help.sendmarc.com/portal-guides?hsLang=en#main-content)

    - [Dashboards & Reports](https://help.sendmarc.com/portal-guides?hsLang=en#dashboards-reports)
    - [Data Interpretation](https://help.sendmarc.com/portal-guides?hsLang=en#data-interpretation)
    - [Domain Management](https://help.sendmarc.com/portal-guides?hsLang=en#domain-management)
    - [Account Management](https://help.sendmarc.com/portal-guides?hsLang=en#account-management)
    - [User Management](https://help.sendmarc.com/portal-guides?hsLang=en#user-management)
    - [On-Demand MSP](https://help.sendmarc.com/portal-guides?hsLang=en#on-demand-msp)
    - [Breach Detection](https://help.sendmarc.com/portal-guides?hsLang=en#breach-detection)
- [Partner Portal Guides](https://help.sendmarc.com/partner-portal-guides?hsLang=en#main-content)

    - [Partner Tools](https://help.sendmarc.com/partner-portal-guides?hsLang=en#partner-tools)
- [Other](https://help.sendmarc.com/other?hsLang=en#main-content)

    - [Scripts](https://help.sendmarc.com/other?hsLang=en#scripts)
- [Integrations](https://help.sendmarc.com/integrations?hsLang=en#main-content)

    - [Abnormal](https://help.sendmarc.com/integrations?hsLang=en#abnormal)
    - [ConnectWise](https://help.sendmarc.com/integrations?hsLang=en#connectwise)
    - [Acronis](https://help.sendmarc.com/integrations?hsLang=en#acronis)
    - [HaloPSA](https://help.sendmarc.com/integrations?hsLang=en#halopsa)
    - [Autotask (Datto) (Kaseya)](https://help.sendmarc.com/integrations?hsLang=en#autotask-datto-kaseya)

[![Chill listening crop-3](https://help.sendmarc.com/hs-fs/hubfs/Sendmarc-Logo.png?width=139&height=24&name=Sendmarc-Logo.png "Chill listening crop-3")](https://sendmarc.com/)

Copyright © 2025, Sendmarc