0 votes

We have created a custom attribute called Decommission Date. I want to create a scheduled task that runs daily that will list in the body of an email users whose decommission date was 45 & 30 days ago from the current date.
Right now, we have something setup where it will send an email for each user whose decommission date was 45 or 30 day ago from current date. However, that can send many emails to the account people. We would like to consolidate that down to one or two emails just with a list of user’s names.

Adaxes version 2017.2
3.8.14823.0

by (1.3k points)
0

Hello,

Could you specify, what details (Name, Description, etc.) on the users you need to be included into the report? Do you need the report embedded into the email notification or attached to the email as a CSV file? An example of the desired report would be very helpful.

0

Just the user's name and embedded into the email.

Example:

Please complete the 30 Day decommission process for the following users:

Robert Drake
Obadiah Stane
Rickey Gibson

Please complete the 45 Day decommission process for the following users:

Barbara Gordon
Dick Grayson
Victor Stone

0

Hello,

Thank you for clarifying. Could you also specify which attribute is used to store the decommission date? If you extended your Active Directory schema with the attribute, also specify its data type.

0

Decommission Date
adm-CustomAttibuteDate4

1 Answer

0 votes
by (272k points)
selected by
Best answer

Hello,

You will need to create a Scheduled Task configured for Domain-DNS object type that will execute the below script. For information on how to create Scheduled Tasks, have a look at the following tutorial: https://www.adaxes.com/tutorials_Automa ... gement.htm. On step 3 of the tutorial, select Show all object types and then select Domain-DNS Object type.

In the script:

  • $propertyName - specifies the LDAP name of the property storing the decommission date;
  • $to - specifies the email address of the notification recipient;
  • $subject - specifies the notification subject.
$propertyName = "adm-CustomAttributeDate1" # TODO: modify me

# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Users report" # TODO: modify me

function SearchObjects($filter, $properties)
{
    $searcher = $Context.BindToObject("Adaxes://rootDSE")
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.SetPropertiesToLoad($properties)
    $searcher.VirtualRoot = $True

    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Search users
$searchResults = SearchObjects "(sAMAccountType=805306368)" @($propertyName, "name")

$firstList = New-Object "System.Text.StringBuilder"
$secondList = New-Object "System.Text.StringBuilder"
$firstDate = [System.DateTime]::Now.AddDays(-30)
$secondDate = [System.DateTime]::Now.AddDays(-45)
foreach ($searchResult in $searchResults)
{
    if (-not($searchResult.ContainsProperty($propertyName)))
    {
        continue
    }

    $date = $searchResult.Properties[$propertyName].Value
    if ($date.Date -eq $firstDate.Date)
    {
        [void]$firstList.AppendLine($searchResult.Properties["name"].Value)
    }
    elseif ($date.Date -eq $secondDate.Date)
    {
        [void]$secondList.AppendLine($searchResult.Properties["name"].Value)
    }
}

# Build message
if (($firstList.Length -eq 0) -and ($secondList.Length -eq 0))
{
    $message = "Now users found"
}
else
{
    $message = New-Object "System.Text.StringBuilder"
    if ($firstList.Length -ne 0)
    {
        [void]$message.AppendLine("Please complete the 30 Day decommission process for the following users")
        [void]$message.AppendLine()
        [void]$message.Append($firstList.ToString())
        [void]$message.AppendLine()
    }

    if ($secondList.Length -ne 0)
    {
        [void]$message.AppendLine("Please complete the 45 Day decommission process for the following users:")
        [void]$message.AppendLine()
        [void]$message.Append($secondList.ToString())
    }
}

# Send mail
$Context.SendMail($to, $subject, $message.ToString(), $NULL)

Related questions

0 votes
1 answer

hello i'm new with Adaxes i'm try to creat schuadle task to import a spefice user list by thier username id after that just update City for them by bulk updating . kinly advise

asked Aug 29, 2023 by sudox (20 points)
0 votes
1 answer

Have a csv file of users that I need to import into Adaxes. I had initially found an article for this, but upon going today, it gave me an error (looks like it was deleted). Thank you

asked Nov 19, 2022 by wangl (20 points)
0 votes
1 answer

I used the script below to try and accomplish this but I get an error. I did try to leave a comment but it would not let me. I tried running ... .adaxes.com/script-repository/add-users-located-in-particular-organizational-units-to-unmanaged-accounts-s178.htm

asked Nov 14, 2022 by raul.ramirez (210 points)
0 votes
0 answers

Hello, Is it possible to pass a comma-separated list of users (firstname.lastname or emails) in a parameter instead of a CSV? How does it translate to an array of usernames ... in the Adaxes interface. Or can the script only email the list of disabled users?

asked Oct 25, 2022 by manomano (80 points)
0 votes
1 answer

Hi, Can you tell me how to look up a list of last logged-in users for computers from specific OU? Have OU called Laptops and need to know who as last person logged into ... username-of-last-user-who-lgged-on-to-computer-s269.htm but it' s not design for OU

asked Dec 2, 2019 by roberttryba (70 points)
3,356 questions
3,055 answers
7,799 comments
545,167 users