Script repository

Create shared and room mailboxes in on-premises Exchange

Updated on: Jan 18, 2026, Views: 8772

Exchange

The scripts create shared and room mailboxes in on-premises Exchange. To execute the scripts, create a business rule, custom command or scheduled task configured for the User object type.

In the scripts, the $exchangeServer variable specifies the fully-qualified domain name of the Exchange server to use.

Shared mailbox

$exchangeServer = "exchangeserver.domain.com" # TODO: Modify me

# Disable the user.
$Context.TargetObject.AccountDisabled = $True
$Context.TargetObject.SetInfo()

# Get the DC that Adaxes uses for the account domain.
$domainName = $Context.GetObjectDomain("%distinguishedName%")
$rootDSE = $Context.BindToObject("Adaxes://$domainName/rootDSE")
$domainControllerFQDN = $rootDSE.Get("dnsHostName")

try
{
    # Connect to Exchange server.
    $session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
    Import-PSSession -session $session

    # Create shared mailboxs
    Enable-Mailbox -Identity '%distinguishedName%' -DomainController $domainControllerFQDN -Shared
}
finally
{
    # Close the remote session and release resources.
    Remove-PSSession -Session $session
}

Room mailbox

$exchangeServer = "exchangeserver.domain.com" # TODO: Modify me

# Disable the user.
$Context.TargetObject.AccountDisabled = $True
$Context.TargetObject.SetInfo()

# Get the DC that Adaxes uses for the account domain.
$domainName = $Context.GetObjectDomain("%distinguishedName%")
$rootDSE = $Context.BindToObject("Adaxes://$domainName/rootDSE")
$domainControllerFQDN = $rootDSE.Get("dnsHostName")

try
{
    # Connect to Exchange server.
    $session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
    Import-PSSession -session $session

    # Create room mailbox.
    Enable-Mailbox -Identity '%distinguishedName%' -DomainController $domainControllerFQDN -Room
}
finally
{
    # Close the remote session and release resources.
    Remove-PSSession -Session $session
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.