Script repository

Delete all user data from mobile devices

Updated on: Jan 18, 2026, Views: 3426

Exchange

The script deletes all user data from all Exchange ActiveSync devices that belong to the user. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.

In the script, the $exchangeServer variable specifies the fully-qualified domain name or IP address of the Exchange server.

$exchangeServer = "Exchangeserver.domain.com" # TODO: modify me

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

    $Target = "%username%"
    Get-ActiveSyncDeviceStatistics -Mailbox $Target | foreach { Clear-ActiveSyncDevice $_.Identity }
}
finally
{
    # Close the remote session and release resources.
    Remove-PSSession -Session $session
}

Comments 2

You must be signed in to comment.

  • kmhuglen87

    kmhuglen87

    I attempt to use this script against a user and i'm running into the following error:

    Couldn't find '{USERNAME}' as a recipient. Stack trace: at , : line 44

    Where USERNAME is the username of the account. i tried changing the Username value to UPN and Email attributes. neither option seems to make a difference. Any ideas?

    • Support

      Support

      Hello,

      The error is not related to the script or Adaxes. It is returned by the Get-ActiveSyncDeviceStatistics cmdlet as it cannot find the account. Such a behaviour can occur if you delete the user somewhere in your script before running the cmdlet.

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.