Hello,
We've currently been running the script below to process the migration of all emails from one account to another when a user is deleted.
What we are hoping to do is track when the email was deleted and what account it was added to in a spreadsheet or just a report.
$userDN = "%assistant%" # TODO: modify me
# Get all E-mail addresses from the target user
try
{
$sourceMailboxParams = $Context.TargetObject.GetMailParameters()
}
catch
{
return # The user doesn't have an Exchange account
}
$sourceEmailAddresses = $sourceMailboxParams.EmailAddresses
# Add the user's e-mail addresses to e-mail addresses of the receiving user
$targetMailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
$targetEmailAddresses = $targetMailboxParams.EmailAddresses
$targetEmailAddresses.OverrideOldValues = $False
$emailAddressesInfo = @()
$date = (Get-Date).AddDays(30).ToString("d")
foreach ($sourceEmailAddress in $sourceEmailAddresses.GetAddressesByPrefix("smtp"))
{
$emailAddress = $targetEmailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$emailAddress.Address = $sourceEmailAddress.Address
$emailAddress.IsPrimary = $False
$targetEmailAddresses.Add("ADS_PROPERTY_APPEND", $emailAddress)
$emailAddressesInfo += $emailAddress.Address + ":$date"
}
Would it be best to process this in a report or add extra line to the script to track this change as we are hoping to remove anything older than 30 days and need to track the time frame.
Any guidance would be appreciated.
JT