Category Archives: Exchange

Installation of New Exchange server

If you ever have installed a new Exchange server in an Active Directory orgainisation that allready have an Exchange server (That’s not so often anymore), you may have discovered that users get Certificate warning in Outlook, unto you have changed the URL’s to match the certificates.

But I found this script on Github: https://gist.github.com/kevinblumenfeld/31b03bf439b1f94f460eb754ef74120e

It copy the settings of all IIS url’s to the new Exchange server, when it found it in Active Directory.
So run this script before the start of the installation, and you will not receive the certificate warnings after the installation.

Add Exchange management Shell to “normal powershell

Here are a script, that you can include in yours script, to add Exchange management shell, to “normal” powershell scripts.

$StopWatch = [System.Diagnostics.StopWatch]::StartNew()
Function Test-Command ($Command)
{
    Try
    {
        Get-command $command -ErrorAction Stop
        Return $True
    }
    Catch [System.SystemException]
    {
        Return $False
    }
}

IF (Test-Command "Get-Mailbox") {Write-Host "Exchange cmdlets already present"}
Else {

    $CallEMS = ". '$env:ExchangeInstallPath\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell "

    Invoke-Expression $CallEMS
$stopwatch.Stop()
$msg = "`n`nThe script took $([math]::round($($StopWatch.Elapsed.TotalSeconds),2)) seconds to execute..."
Write-Host $msg
$msg = $null
$StopWatch = $null
}

Move from Office 365 to Onpremise in a Hybrid enviroment

import-module msonline
(install-module msonline)

$O365CREDS = Get-Credential
$ONPREMCREDS = Get-Credential #used UPN Username

$SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365CREDS -Authentication Basic -AllowRedirection

Import-PSSession $SESSION
Connect-MsolService -Credential $O365CREDS

#You can run these commands, to check for old MoveRequest or all mailbox in Office365, just remove the hash.
#get-moverequest
#get-mailbox

get-mailbox -id MAILBOX | New-MoveRequest -OutBound -RemoteTargetDatabase DB01 -RemoteHostName owa.domain.prefix -RemoteCredential $ONPREMCREDS -TargetDeliveryDomain ‘InternalAdDomain.prefix’
#Replace MAILBOX with the mailbox
# Replace owa.domain.prefix with the public owa address
# Replace InternalAdDomain.prefix with the internal ad domain name

#You can then run the following commands to check the mailbox moverequest status
Get-MoveRequest | Get-MoveRequestStatistics

Be aware that the user need to be an locally AD users, before you can migrated it back. It can’t be a Cloud users.
See here how to connect the user to an AD user: https://www.codetwo.com/admins-blog/how-to-merge-an-office-365-account-with-an-on-premises-ad-account-after-hybrid-configuration/

Exchange and TLS problems

Today i have a problem that an exchange will not send mails though TLS, no matter what i do.

I find out that, somehow this exchange servers where creating new send connector, with forcehelo = True.

Witch mean that the Exchange server is using the OLD HELO instead of the EHLO, when talking to other SMTP servers. Setting this to false help. Now the Exchange server send with TLS.

So FORCEHELO=$TRUE breaks TLS.

To see if this is the problem, you can type:

get-sendconnector | select id, forcehelo

To set it to false, for the send connector “Default_OUT” you can run this powershell command:

get-sendconnector -id Default_OUT | set-sendconnector -forcehelo $false

Also you might need to set the TLS certificate to the right certificate. Remember that the certificate need to have the hostname in the certificate. Se more on this link:

https://practical365.com/exchange-server/configuring-the-tls-certificate-name-for-exchange-server-receive-connectors/

Error when trying to remove a Mailbox Database on Exchange Server

When you try to delete a mailbox, you may get this error:

This mailbox database contains one or more mailboxes, mailbox plans, archive mailboxes, public folder mailboxes or
arbitration mailboxes. To get a list of all mailboxes in this database, run the command Get-Mailbox -Database
Database ID. To get a list of all mailbox plans in this database, run the command Get-MailboxPlan. To get a list of
archive mailboxes in this database, run the command Get-Mailbox -Database Database ID -Archive. To get a list of all
public folder mailboxes in this database, run the command Get-Mailbox -Database Database ID -PublicFolder. To get a
list of all arbitration mailboxes in this database, run the command Get-Mailbox -Database Database ID -Arbitration.
To disable a non-arbitration mailbox so that you can delete the mailbox database, run the command Disable-Mailbox
Mailbox ID. To disable an archive mailbox so you can delete the mailbox database, run the command Disable-Mailbox
Mailbox ID -Archive. To disable a public folder mailbox so that you can delete the mailbox database, run the command
Disable-Mailbox Mailbox ID -PublicFolder. Arbitration mailboxes should be moved to another server; to do this, run
the command New-MoveRequest Parameters. If this is the last server in the organization, run the command
Disable-Mailbox Mailbox ID -Arbitration -DisableLastArbitrationMailboxAllowed to disable the arbitration mailbox.
Mailbox plans should be moved to another server; to do this, run the command Set-MailboxPlan MailboxPlan ID
-Database Database ID.
    + CategoryInfo          : InvalidOperation: (Database ID:DatabaseIdParameter) [Remove-MailboxDatabase], AssociatedUserMailboxExistException
    + FullyQualifiedErrorId : [Server=Server,RequestId=RequestId,TimeStamp=TimeStamp] [FailureCategory=Cmdlet-AssociatedUserMailboxExistException] XXXXXXXX,Microsoft.Exchange.Management.SystemConfigurationTasks.RemoveMailboxDatabase
    + PSComputerName        : Computer Name

This is because the mailbox database still contains data, that need to be moved, before you can deleted it.
If you run Exchange 2013, run these commands to check witch data, that are still located in the database.

Get-Mailbox -Database "Database" 
Get-Mailbox -Database "Database" -Archive
Get-Mailbox -Database "Database" -Arbitration
Get-Mailbox -Database "Database" -PublicFolder

In Exchange 2016, a new mailbox type is introduce call Auditlog. So here you also need to run this command

Get-Mailbox -Database "Database" -AuditLog

Problems deleting a old mailbox database

I have a customer, where we have taken over the support from an old supplier, so we don’t know much about their background.

The first thing we do, was to update the Exchange Server.
But after have move all mailboxes, public folders, system mailbox.

I still got this error:

This mailbox database contains one or more mailboxes, mailbox plans, archive mailboxes, or arbitration mailboxes. To ge
t a list of all mailboxes in this database, run the command Get-Mailbox -Database <Database ID>. To get a list of all m
ailbox plans in this database, run the command Get-MailboxPlan. To get a list of archive mailboxes in this database, ru
n the command Get-Mailbox -Database <Database ID> -Archive. To get a list of all arbitration mailboxes in this database
, run the command Get-Mailbox -Database <Database ID> -Arbitration. To disable a non-arbitration mailbox so that you ca
n delete the mailbox database, run the command Disable-Mailbox <Mailbox ID>. To disable an archive mailbox so you can d
elete the mailbox database, run the command Disable-Mailbox <Mailbox ID> -Archive. Arbitration mailboxes should be move
d to another server; to do this, run the command New-MoveRequest <parameters>. If this is the last server in the organi
zation, run the command Disable-Mailbox <Mailbox ID> -Arbitration -DisableLastArbitrationMailboxAllowed to disable the
arbitration mailbox. Mailbox plans should be moved to another server; to do this, run the command Set-MailboxPlan <Mail
boxPlan ID> -Database <Database ID>.

Mailbox Plan is only used on the cloud.

I have look every places, unto i run this command:

dsquery * domainroot -attr * -limit 0 > result.txt

i then open the result.txt in notepad, and found some reference to the old database

msExchDisabledArchiveDatabaseLink: CN=Exch2013MB_Archive,CN=Databases,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Fibia,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=XXXX,DC=local

After delete this reference, i could delete the database.

 

 

 

Give access to calendar based on the user is member of the group.

If you need to give auser access to users calendar, based on if there are member of an group, this is the way.
Start Exchange Management Shell

$users = Get-ADGroupMember [groupname] | select -ExpandProperty name
foreach ($user in $users) {
    $Mailbox = Get-Mailbox $user
	#The Calendar, is name "Kalender" in danish
	add-MailboxFolderPermission -identity “$($Mailbox.Name):\kalender” -AccessRights Editor -User [username]
	set-MailboxFolderPermission -identity “$($Mailbox.Name):\kalender” -AccessRights Editor -User [username]

	#English calendar
	add-MailboxFolderPermission -identity “$($Mailbox.Name):\calendar” -AccessRights Editor -User [username]
	set-MailboxFolderPermission -identity “$($Mailbox.Name):\calendar” -AccessRights Editor -User [username]
} 

Exchange: Get a list of all email address

For en liste over alle mail adresse

Get-recipient -resultsize unlimited | select name -expand emailaddresses | select name,smtpaddress

For en liste over alle mail adresse på et given domæne

Get-Recipient | Where{$_.EmailAddresses -match "it-grp.dk"} | select name -expand emailaddresses | select name,smtpaddress | where {$_ -match "kennethdalbjerg.dk"}

Search exchange message tracking log for a particular subject

If you want to search Exchange log for a particular subject, or just a bite of it, you can search witch this commands.

This will also export it to a nice CSV files.

Get-MessageTrackingLog -resultsize unlimited | Where-object {$_.MessageSubject -like "*Kenneth Dalbjerg"} | select-object timestamp,Sender,@{l="Recipients";e={$_.Recipients -join " "}},messageSubject | export-csv c:\KennethDalbjerg.csv