0 votes

We have groups that have nested groups that have members.

(How our nested groups are setup. One user can be part of more than on group.)

I need one CSV with name and email address created of all the users in the highest level group emailed to me.
I'm want to setup a scheduled task to do this monthly but the only scripts I have found make a CSV for each of the nested groups and not the "all-Users" group

I would like any and all help that is given.

Thank you,

by (1.3k points)
0

Hello,

What version of Adaxes are you currently using? To check that:

  1. Launch Adaxes Administration Console.
  2. Right-click your service.
  3. Click Properties in the context menu.
  4. Adaxes version is displayed on the General tab.
0

I'm on 3.8.14823.0

1 Answer

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

Hello,

Have a look at the following script from our repository: https://www.adaxes.com/script-repositor ... e-s184.htm.
For the report to include only direct group members, replace the line

$memberGuidsBytes = $Context.TargetObject.GetEx("adm-MembersGuid")

with the following:

$memberGuidsBytes = $Context.TargetObject.GetEx("adm- DirectMemberOfGuid")

To send the CSV file attached to an email notification, use the Send-MailMessage cmdlet.

Should you have difficulties updating the script to meet your needs, provide us with all the possible details on the resulting CSV file (columns, sorting, etc.) and we will help you.

0

I need the in-direct members because the "All-Users" group does not contain users directly only the groups for the offices they are in. The office groups contains the users. Also I need one CSV, that script makes a new CSV for each nested group. which is not what I need. I need the user's name and email address only in the CSV

0

Hello,

We have updated the script to meet your needs, find it below. To run the script, you can use a Custom Command, Scheduled Task, etc. configured for Group object type. In the script:

  • $csvFilePath - specifies a UNC path to the CSV file that will be created by the script;
  • $removeCSVFile - specifies whether to remove the CSV file after it has been sent;
  • $sortColumns - specifies the columns to sort by;
  • $sortDirection - specifies the sort direction;
  • $to - specifies a comma separated list of recipients of the report;
  • $subject - specifies the email message subject;
  • $message - specifies the email notification message;
  • $from - specifies the notification sender;
  • $smtpServer - specifies the SMTP server to use when sending a notification.
# CSV file settings
$csvFilePath = "C:\reports\report.csv" # TODO: modify me
$removeCSVFile = $True # TODO: modify me

# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Group members" # TODO: modify me
$message = "Group members" # TODO: modify me
$from = "noreply@domain.com" # TODO: modify me
$smtpServer = "mail.domain.com" # TODO: modify me

function GetPropertyValue ($object, $propertyName)
{
    try
    {
        $value = $object.Get($propertyName)
    }
    catch
    {
        $value = $NULL
    }

    return $value
}

$now = [System.DateTime]::Now.ToString("yyyy.MM.dd.HH.mm.ss")
$csvFilePath = [System.String]::Format($csvFilePath, $now)

# Get group members
try
{
    $memberGuidsBytes = $Context.TargetObject.GetEx("adm-MembersGuid")
}
catch
{
    $Context.LogMessage("The group has no members. No CSV file will be created.", "Warning")
    return # Exit script
}

# Build report
$report = @()
foreach ($memberGuidBytes in $memberGuidsBytes)
{
    # Bind to the group member
    $memberGuid = New-Object "System.Guid" (, $memberGuidBytes)
    $memberGuid = $memberGuid.ToString("B")
    $memberPath = "Adaxes://<GUID=$memberGuid>"
    $member = $Context.BindToObject($memberPath)

    # Add member information to the report
    $memberName = GetPropertyValue $member "cn"
    $memberEmail = GetPropertyValue $member "mail"

    $reportEntry = New-Object PSObject
    $reportEntry | Add-Member -Name Name -Value $memberName -MemberType NoteProperty
    $reportEntry | Add-Member -Name Email -Value $memberEmail -MemberType NoteProperty    
    $report += $reportEntry
}

# Export report to CSV
$report | Sort-Object "Name" | Export-Csv -Path $csvFilePath -NoTypeInformation

# Send mail
Send-MailMessage -To $to -from $from -SmtpServer $smtpServer -Subject $subject -Body $message -Attachments $csvFilePath

if ($removeCSVFile)
{
    # Remove temporary file
    Remove-Item $csvFilePath -Force
}

Related questions

0 votes
1 answer

We have a 3rd party vendor that we are able to add users based on AD security groups. What I need to do is set a parameter for the number of available licenses and whenever ... the group is 495 I would like an email to trigger telling me to add more licenses.

asked Oct 12, 2022 by A_Pastor (70 points)
0 votes
1 answer

So this works for us however we would like to add to check if the last group is at 3 users we would like to send a seperate email but would still like all the above to continue to happen the way it is.

asked Mar 2, 2022 by Keonip (160 points)
0 votes
1 answer

I would like to on a monthly basis to email the group owner the members of each group they own for verification pruposes. i would need the group name and the name of the members.

asked Jun 3, 2021 by Derek.Axe (480 points)
0 votes
1 answer

I am looking for a way to make the Owners of groups review members in those groups every 6 months and approve\deny the members of said group. Flow would be something like this ... of the group. So if they didnt approve it, the user would no longer have access.

asked 6 hours ago by ADuser (20 points)
0 votes
1 answer

Hi team, I have a follow up to this question https://www.adaxes.com/questions/14234/business-after-adding-members-powershell-script-executed Let me explain my setup A rule- ... area% failed due to the following exception: $($_.Exception.Message)", "Error") }

asked Feb 13 by wintec01 (1.1k points)
3,361 questions
3,060 answers
7,810 comments
545,215 users