0 votes

We had asked for help before for this process and Adaxes Tech's sent us a script, now the users of the results of the script have request some changes. Some of the changes we figured out how to incorporate into the script, the others not so much...here is what we are asking for:
1. Useing the web interface, be able to identify the user and have the result of the script sent back to that user.
2. the result is currently a HTML email, the change is to convert the result to a .csv file and send that to the requesting user.

Here is the script:

# Email message setings
$to = "dk@emailcompany.com" (changed to not have company info.)
$subject = "Org Chart Rollup"
$htmlReportHeader = @"
<h1><b>Full List of Subordinates for %name%</b></h1><br/>
<table border="1">
    <tr>
        <th>Manager Name</th>
        <th>Manager Job Title</th>
        <th>Employee Name</th>
        <th>Employee Job Title</th>
        <th>Department</th>
        <th>Employee ID</th>
    </tr>
"@ # TODO: modify me

$htmlReportFooter = @"
</table><br/>

<p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>
"@ # TODO: modify me

function GetAllSubordinates($directReportDN, $subordinates, $managerName, $managerJobTitle, $userDepartment, $userEmployeeID)
{
    if($subordinates.ContainsKey($directReportDN))
    {
        return
    }

    # Bind to Subordinate
    $user = $Context.BindToObjectByDN($directReportDN)

    # Get user name
    $userName = $user.Get("name")

    # Get user job title
    try
    {
        $userJobTitle = $user.Get("title")
    }
    catch
    {
        $userJobTitle = "&nbsp;"
    }

    # Get user Department
    try
    {
        $userDepartment = $user.Get("department")
    }
    catch
    {
        $userDepartment = "&nbsp;"
    }

    # Get user Employee ID
    try
    {
        $userEmployeeID = $user.Get("employeeID")
    }
    catch
    {
        $userEmployeeID = "&nbsp;"
    }

    # Add to HashTable
    $userInfo = New-Object PSObject
    $userInfo | add-member Noteproperty ManagerName $managerName
    $userInfo | add-member Noteproperty ManagerJobTitle $managerJobTitle
    $userInfo | add-member Noteproperty UserName $userName
    $userInfo | add-member Noteproperty UserJobTitle $userJobTitle
    $userInfo | add-member Noteproperty UserDepartment $userDepartment
    $userInfo | add-member Noteproperty UserEmployeeID $userEmployeeID

    $subordinates.Add($directReportDN, $userInfo) | Out-Null

    # Get Subordinates
    try
    {
        $directReportDNs = $user.GetEx("directReports")
    }
    catch
    {
        return
    }

    foreach ($directReportDN in $directReportDNs)
    {
        GetAllSubordinates $directReportDN $subordinates $userName $userJobTitle $userDepartment $userEmployeeID
    }
}

# Get subordinates
try
{
    $directReportDNs = $Context.TargetObject.GetEx("directReports")
}
catch
{
    $Context.LogMessage("The user doesn't have any direct reports.", "Error") # TODO: modify me
    return
}

$subordinates = New-Object "System.Collections.Hashtable" 
foreach ($directReportDN in $directReportDNs)
{
    GetAllSubordinates $directReportDN $subordinates "%name%" "%title%" "%department%" "%employeeID%"
}

# Sort list
$subordinates = $subordinates.Values | Sort-Object -Property @{Expression={$_.ManagerName}; Ascending=$True}

# Build HTML report
foreach ($subordinate in $subordinates)
{
    $htmlReportHeader += "<tr><td>" + $subordinate.ManagerName + "</td>"
    $htmlReportHeader += "<td>" + $subordinate.ManagerJobTitle + "</td>"
    $htmlReportHeader += "<td>" + $subordinate.UserName + "</td>"
    $htmlReportHeader += "<td>" + $subordinate.UserJobTitle + "</td>"
    $htmlReportHeader += "<td>" + $subordinate.UserDepartment + "</td>"
    $htmlReportHeader += "<td>" + $subordinate.UserEmployeeID + "</td></tr>"
}
$htmlBody = $htmlReportHeader + "</table>" + $htmlReportFooter

# Send the report
$Context.SendMail($to, $subject, $NULL, $htmlBody)

Thank you for your help.

Anthony Babbe

by (320 points)
0

Hello,

We've asked our script guys to change the script for you. We'll update you as soon as they come up with something.

0

Support,

Is there any update on this.

Thank you,

Tony Babbe

1 Answer

0 votes
by (216k points)

Hello Tony,

The script is ready. In the new version of the script:

  • $csvFilePath specifies the path to the CSV file that will be generated and attached to an e-mail notification,
  • $to - specifies the recipient of the report,
  • $from - specifies the e-mail address that will be displayed as the report sender,
  • $smtpServer - specifies an SMTP server to be used for sending reports,
  • $subject - specifies the e-mail message subject,
  • $messageBody - specifies the e-mail message body (in plain text form).

The script:

$csvFilePath = "c:\temp\report.csv" # TODO: modify me

# Email message setings
$to = "dk@emailcompany.com" # (changed to not have company info.)
$from = "noreply@domain.com" # TODO: modify me
$smtpServer = "mail.domain.com" # TODO: modify me
$subject = "Org Chart Rollup"
$messageBody = "Full List of Subordinates for %name%" # TODO: modify me

function GetAllSubordinates($directReportDN, $subordinates, $managerName, $managerJobTitle, $userDepartment, $userEmployeeID)
{
    if($subordinates.ContainsKey($directReportDN))
    {
        return
    }

    # Bind to Subordinate
    $user = $Context.BindToObjectByDN($directReportDN)

    # Get user name
    $userName = $user.Get("name")

    # Get user job title
    try
    {
        $userJobTitle = $user.Get("title")
    }
    catch
    {
        $userJobTitle = $NULL
    }

    # Get user Department
    try
    {
        $userDepartment = $user.Get("department")
    }
    catch
    {
        $userDepartment = $NULL
    }

    # Get user Employee ID
    try
    {
        $userEmployeeID = $user.Get("employeeID")
    }
    catch
    {
        $userEmployeeID = $NULL
    }

    # Add to HashTable
    $userInfo = New-Object PSObject
    $userInfo | add-member Noteproperty ManagerName $managerName
    $userInfo | add-member Noteproperty ManagerJobTitle $managerJobTitle
    $userInfo | add-member Noteproperty UserName $userName
    $userInfo | add-member Noteproperty UserJobTitle $userJobTitle
    $userInfo | add-member Noteproperty UserDepartment $userDepartment
    $userInfo | add-member Noteproperty UserEmployeeID $userEmployeeID

    $subordinates.Add($directReportDN, $userInfo) | Out-Null

    # Get Subordinates
    try
    {
        $directReportDNs = $user.GetEx("directReports")
    }
    catch
    {
        return
    }

    foreach ($directReportDN in $directReportDNs)
    {
        GetAllSubordinates $directReportDN $subordinates $userName $userJobTitle $userDepartment $userEmployeeID
    }
}

# Get subordinates
try
{
    $directReportDNs = $Context.TargetObject.GetEx("directReports")
}
catch
{
    $Context.LogMessage("The user doesn't have any direct reports.", "Error") # TODO: modify me
    return
}

$subordinates = New-Object "System.Collections.Hashtable"
foreach ($directReportDN in $directReportDNs)
{
    GetAllSubordinates $directReportDN $subordinates "%name%" "%title%" "%department%" "%employeeID%"
}

# Sort list
$subordinates = $subordinates.Values | Sort-Object -Property @{Expression={$_.ManagerName}; Ascending=$True}

# Export to the temp csv file
$subordinates | Export-Csv -Path $csvFilePath -NoTypeInformation

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

# Remove temp arrchive
Remove-Item $csvFilePath -Force
0

How do I get this to send to the person who is requesting the org chart from the Web interface?
The current "To" line has a single address receiveing the all of the requests, but they want the person requesting the chart to get the chart back via the request.

# Email message setings  
$to = "<dk@emailcompany.com>" \# (changed to not have company info.)  
$from = "<noreply@domain.com>" # TODO: modify me  
$smtpServer = "mail.domain.com" # TODO: modify me  

Thanks again,

Tony

0

Tony,

For this purpose, simply replace dk@emailcompany.com with %adm-InitiatorEmail%:

# Email message setings
$to = "%adm-InitiatorEmail%"

Related questions

0 votes
1 answer

Every manager has an overview, where you can see to whom he/she is reporting to and who is reporting to the manager. This will be visible in Microsoft teams ... purpose for this is to use it for email communication (account/password expiration notifications).

asked Jul 4, 2022 by RoBeDi (60 points)
0 votes
1 answer

Hi, we just recently installed Adaxes and would like to implement a PowerShell script that I have previously written which cleans up user objects if they have been manually ... to perform the operation Stack trace: at &lt;ScriptBlock&gt;, &lt;No file&gt;".

asked Oct 2, 2023 by Mark.Monaco (20 points)
0 votes
1 answer

Can anyone provide the instructions contain in the now broken link? I realize new Adaxes doesn't require this, but still have an older install that doesn't allow manual override via GUI. Thanks.

asked Oct 13, 2022 by okiad (20 points)
0 votes
1 answer

We have password self-service enabled with users adding their questions, but was wondering if we could dispaly those answers to the help desk so that they can confirm that the user calling in is actually them? Is there an option to do somnething like that?

asked Mar 16, 2022 by seannicholas71 (20 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, 2020 by jcalvert (60 points)
3,342 questions
3,043 answers
7,766 comments
544,933 users