0 votes

I have a scheduled task that runs a PowerShell script. The script checks various properties of each user, and uses $Context.LogMessage to report on properties that are not formatted properly.

Currently if I set an action to Send an email, an email will be generated for every user. How can I combine all of these LogMessages (doesn't have to be LogMessage) into a single report or single notification email?

by (250 points)
0

Hello,

For us to suggest a solution, please, post here or send us (support[at]adaxes.com) a screenshot of the Scheduled Task and the script being executed.

0

Hi,

Scheduled Task is very simple, just executes a Custom Command image.png

Custom Command is a PowerShell script

$username = '%username%'
$upn = '%userPrincipalName%'
$mail = '%mail%'
$alias = '%mailNickname%'

Import-Module Adaxes
# Username Checks
if ($username -cne $username.ToLower()) {
    $Context.LogMessage("Username $username is not lowercase", 'Warning')
}

# UPN checks
if ($upn -cne $upn.ToLower()) {
    $Context.LogMessage("UPN $upn is not lowercase", 'Warning')
}
if ($upn -ne "$username@example.com") {
    $Context.LogMessage("UPN $upn is not in format of username@example.com", 'Warning')
}

# Email checks
if ($mail -and $mail -cne $mail.ToLower()) {
    $Context.LogMessage("Email $mail is not lowercase", 'Warning')
}
if ($alias -and $alias -cne $alias.ToLower()) {
    $Context.LogMessage("Alias $alias is not lowercase", 'Warning')
}

I just want to combine results of the script so I can get a report of incorrectly formatted properties.

Thanks

0

Hello,

Thank you for the provided details. It can be done by updating the script you have. For us to provide you with the updated script, please, specify what should be done if a specific property (e.g. Email) is empty? Should the corresponding message be added to the email notification? A live example of the email notification would also be very helpful.

0

If mail or mailNickname are blank, that's fine, no warning should be given.

I just need a way to get notified of all the incorrectly formatted properties in one consolidated report. If I set the custom command to Email, it gives me an email for each user.

1 Answer

0 votes
by (187k points)

Hello,

Thank you for the confirmation. It can be done using a report. For information on how to create a report, have a look at the following tutorial: https://www.adaxes.com/tutorials_ActiveDirectoryManagement_CreateReport.htm. In the report, use the below script. In the script, the $validUpnDomain variable specifies the domain part that will be used to validate UPNs.

$validUpnDomain = "example.com" # TODO: modify me

$Context.DirectorySearcher.AppendFilter("(sAMAccountType=805306368)")
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("mail")
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("sAMAccountName")
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("userPrincipalName")
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("mailNickname")

try
{
    $searchIterator = $Context.DirectorySearcher.ExecuteSearch()
    while ($Context.MoveNext($searchIterator))
    {
        $searchResult = $searchIterator.Current
        $sAMAccountName = $searchResult.GetPropertyByName("sAMAccountName").Values[0]
        $mail = $searchResult.GetPropertyByName("mail").Values[0]
        $userPrincipalName = $searchResult.GetPropertyByName("userPrincipalName").Values[0]
        $mailNickname = $searchResult.GetPropertyByName("mailNickname").Values[0]

        $valiedUserName = "$sAMAccountName@$validUpnDomain"
        if ($sAMAccountName -cmatch "[A-Z]")
        {
            $Context.Items.Add($searchResult)
        }
        elseif ($userPrincipalName -cmatch "[A-Z]")
        {
            $Context.Items.Add($searchResult)
        }
        elseif ($userPrincipalName -ne $valiedUserName)
        {
            $Context.Items.Add($searchResult)
        }
        elseif ($mail -cmatch "[A-Z]")
        {
            $Context.Items.Add($searchResult)
        }
        elseif ($mailNickname -cmatch "[A-Z]")
        {
            $Context.Items.Add($searchResult)
        }
    }
}
finally
{
    if ($searchIterator) { $searchIterator.Dispose() }
}

For information on how to schedule reports delivery, have a look at the following tutorial: https://www.adaxes.com/tutorials_ActiveDirectoryManagement_ScheduleReports.htm.

Related questions

0 votes
1 answer

Is there a way to have a Scheduled Task run a Powershell script on the 1st and 3rd Wednesday of every month? Adaxes Version 2017.2 3.8.14823.0

asked Jun 24, 2019 by hgletifer (6.8k points)
0 votes
1 answer

We are using Adaxes to manage multiple domains. upwards of 10 domains. There is no trust between the domains. The are all separate stand alone. We want to setup a scheduled ... domain has an Adaxes service account setup and that is what i would want to use.

asked Sep 14 by gt_111 (250 points)
0 votes
1 answer

I am trying to send a $context.logmessage from a condition script in a Scheduled Task but I get nothing in the log. Is this not possible? Morten A. Steien

asked Jul 20 by Morten A. Steien (280 points)
0 votes
0 answers

I am creating a new scheduled task and form. We would like to have the ability to schedule the reassignment of a staff member to a different location in the future. ... context, my manager won't necessarily know when he tries to move somebody. Thanks everybody

asked May 21 by jcalvert (650 points)
0 votes
1 answer

Hi, I need to start Adaxes scheduled task from Powershell console running on another host. How can I do that?

asked May 21 by KIT (3.1k points)
2,330 questions
2,085 answers
5,671 comments
92,786 users