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 (60 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 (220k 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

My scheduled task works like this (these are my action sets) Condition(s): Account is expired and home drive exists Action The user's home directory gets archived Condition(s): ... set? I do not want to split the scheduled task into two! Thanks in avance!

asked Apr 7 by lehnen (20 points)
0 votes
1 answer

Currently, when I disable a user account in Adaxes, the group memberships of the user remain intact. I'd like to automate the removal of group memberships such as distribution ... a list of groups/DL that the user was previously in and removed from. Thanks!

asked Nov 3, 2021 by jayden.ang (20 points)
0 votes
1 answer

On Approval Requests, in the web console, Initiator shows "N/A" instead of the custom command scheduled task. The admin console shows the custom command scheduled task though. Any way to fix that?

asked Jan 21, 2021 by mark.it.admin (1.8k points)
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 (1.2k points)
0 votes
1 answer

Is there a way to have a Scheduled Task with 4 different condition? I want to create a scheduled task start every Monday and the condition see: The next Saturday of the week ... of the week is the fifth of the month then no action Thanks in advance, Simone

asked Jan 18 by Simone.Vailati (250 points)
2,740 questions
2,474 answers
6,475 comments
1,373,514 users