0 votes

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

by (700 points)
0

Hello,

Sorry for the confusion, but we are not sure what exactly you need to achieve. The script you provided adds Email addresses (not emails) from the target user to their assistant. Please, describe the desired behavior in all the possible details with live examples and screenshots.

0

Hello, sorry for the confusion, yes this does strip the email addressess.

Our full request is as follows:

  1. We run this script when we delete a user, stripping the email addresses and appending them to an existing users list of email addresses (this is already accomplished by the script)
  2. The main goal of this request is to basically output either the email addresses that are being pulled or the account they were pulled from and a date stamp.

We don't have any preference if this occurs in the script or via a pre-existing report built into Adaxes (whichever makes the most sense).

1 Answer

0 votes
by (294k points)

Hello,

The addresses are always pulled from the target user to their assistant. As such, you can use the below approach to output the details to the execution log.

$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")

$Context.LogMessage("The below addresses are transferred from %fullname% to %adm-AssistantFullName% until $date", "Information")
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)

    $Context.LogMessage($sourceEmailAddress.Address, "Information")

    $emailAddressesInfo += $emailAddress.Address + ":$date"
}
0

just curious if there is a way to output that specific information or review it in reports?

reasoning is we need to remove these email addresses from the accounts they were migrated to after 30 days (either manually or automatically).

haveing the log output in some sort of report or spreadsheet would be the ultimate goal so we can review and remove based on that.

image.png

0

Hello,

Unfortunately, there is no such possibility as the information is available only during the script execution.

0

would there be a possibility to add the information to a file from the script?

No worries if not, I have some ideas if we cannot.

0

Hello,

Yes, it is possible right in this very script. You can use value references to form file names so that they refer to the corresponding user accounts.

0

any suggestions on best process for this? unfortunately I'm not much of a coder, I can try and figure this out, but your assistance has been crucial thus far.

0

Hello,

It totally depends on your requirements on the file and its contents. The following article will be helpful:

0

just would need to export the either the emails or the account and the date of expiration to a csv, that would be perfect.

0

Hello,

Here is an example of the script you might use. We added the $filePath varialbe specifying the path to the file that will be created by the script.

$userDN = "%assistant%" # TODO: modify me
$filePath = "d:\Deprosisioned user emails\%fullname%.txt" # 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")

Out-File -FilePath $filePath -InputObject "The below addresses are transferred from %fullname% to %adm-AssistantFullName% until $date"

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)

    Out-File -FilePath $filePath -InputObject $sourceEmailAddress.Address -Append

    $emailAddressesInfo += $emailAddress.Address + ":$date"
}

Related questions

0 votes
1 answer

We are using the below snippet to grab the email of a single custom attribute object. Can I get guidance on the best way to modify this to get all the emails of each ... "The user specified in parameter 'MyParameter' has no email address. ", "Information") }

asked 2 days ago by msheppard (660 points)
0 votes
1 answer

Hello, I am looking for a way with a custom command or script to change ExtensionAttribute4 for all users in a specific OU(and Sub-OU's). Currently all of the ... change them to firstname.lastname@yyy.com just changing the field after the @ symbol. Thank You

asked Mar 19, 2016 by Infounlim (470 points)
0 votes
1 answer

Dear Support, we try to use a "Custom Business Unit" in a "Property Pattern" for excluding OUs, but it doesn't works. We created a Business Unit called "Service OUs ... Membership Rules is the following filter set: Do you know whats wrong in my Business Unit?

asked Jan 28, 2014 by Napoleon (700 points)
0 votes
1 answer

Hello, I'm wondering if it's possible to export a list of all users in AD along with their email addresses to an Excel spreadsheet and then schedule that export to append ... address that wasn't previously used. Please let me know if this is possible. Thanks!

asked Apr 11 by sjjb2024 (60 points)
0 votes
1 answer

We have a rather manual process that we follow here when we have a user that changes from one role to another...and the user still needs access of both roles for a short ... we're looking for (A users object's group membership to a group). Thoughts? Thanks!

asked Sep 11, 2018 by AdaxesUser1985 (140 points)
3,589 questions
3,278 answers
8,303 comments
548,130 users