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 (100 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 (289k 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

Using the powershell module, I know how to create a scheduled task, and also how to bind to a scheduled task that is already known. I also have used code to try creating ... same time as another. These are all one-time tasks and will be removed once executed.

asked Jan 19 by aweight (60 points)
0 votes
1 answer

The script create two reports of inactive workstation operating systems. The report is too detailed to run from one of the adaxes reports. Basically how can I set the script up to ... sure How I did this but I can't find it now (probably something simple).

asked Nov 30, 2022 by mightycabal (1.0k points)
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, 2022 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 (2.3k points)
3,550 questions
3,241 answers
8,235 comments
547,827 users