MVP - Most Valuable Professional
rss

Just can't get enough of IT

This blog is about mostly anything in IT. But the primary focuses are Microsoft Technologies like Exchange, Office 365, Azure and Cloud Security.

Cleanup Mobile Device Partnerships

Last updated: 2020-02-29

 

This is the Modern Exchange Server version for 2013, 2016, and 2019. Find the PowerShell version for Exchange 2010 here.

 

Exchange Server 2013Exchange Server 2016Exchange Server 2019Description

This script removes orphaned mobile device partnerships from Exchange Server 2013+ user mailboxes. Run the script as a scheduled task to maintain your Exchange Server environment properly.

This script utilizes a settings.xml file to configure

  • SMTP settings for email reports
  • Threshold values for mobile devices
    • The default number of allowed devices per user: 5
    • The default number of aged devices to be removed: 1
    • The default threshold for unsynchronized devices: 150 days

Settings.xml (default)

<?xml version="1.0"?>
<Settings>
  <EmailSettings>	
    <SMTPServer>smtp.mcsmemail.de</SMTPServer>
    <SMTPPort>25</SMTPPort>
    <MailFrom>postmaster@mcsmemail.de</MailFrom>
    <MailTo>postmaster@mcsmemail.de</MailTo>
  </EmailSettings>
  <OtherSettings>
	<!-- MobileDeviceLimit defines the overall threshold of mobile devices for a single user to synchronize. Default is 5. -->
	<MobileDeviceLimit>5</MobileDeviceLimit>

	<!-- AgedDeviceLimit defines the threshold of allowed aged devices for a single user to be removed. Default is 1. -->
	<AgedDeviceLimit>1</AgedDeviceLimit>

	<!-- Time threshold in days to identify old mobile devices, Be default devices not synchronized for 150 days will be removed -->
    <LastSyncDays>150</LastSyncDays>
  </OtherSettings>
</Settings>

Steps being executed by the script:

  1. Fetch all user mailboxes hosted on Exchange Server 2013 or newer
  2. Iterate through each user mailbox and determine the number of mobile devices and the number of devices which have not synchronized for 150 days
  3. Remove mobile device registration, if a user has more than the allowed number of devices in total and a minimum of 1 device that has not synced within 150 days and the -ReportOnly switch has not been used
  4. Optionally, write a CSV export of identified mobile devices to disk | Use -ReportOnly switch
  5. Optionally, send an email report | Use -SendMail switch

 

Requirements

  • Exchange Server 2013, 2016, 2019
  • Windows Server 2012 R2 or newer
  • Exchange Management Shell

 

Examples

# Example 1
# Remove old mobile device partnerships without sending a report email

 .\Remove-MobileDevicePartnership.ps1 

# Example 2
# Remove old mobile device partnerships and send a report email

.\Remove-MobileDevicePartnership.ps1 -SendMail

# Example 3
# Search for old mobile device partnerships and write results as CSV to disk

.\Remove-MobileDevicePartnership.ps1 -ReportOnly

# Example 4
# Remove old mobile device partnerships for a single mailbox and send a report email

 .\Remove-MobileDevicePartnership.ps1 -MailboxFilter USERALIAS -SendMail

 

Version History

  • 1.0, Initial community release
  • 1.1, ReportOnly switch added
  • 2.0, Updated script to support Exchange Server 2019, parameter MailboxFilter added

 

Links

 

Follow

 

 



Comments are closed.

Showing 0 Comment