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

I am noticing a large amount of PowerShell Transcript files in the Adaxes SA accounts Documents folder. These are different than the logging feature which has a very ... Can I configure these transcripts in any way to manage their space consumption/retention?

asked Nov 5 by SysADM (50 points)
0 votes
1 answer

Hi so if I have the web-interface setup on my internal server where I did the full install but I also have setup a RODC in DMZ how can I "merge" so that the URLS given ... get the offline/unlock that shows up to link and show/work for the web server on the DMZ

asked Nov 4 by ckelley (40 points)
0 votes
1 answer

I am trialing out the product and having some trouble/challenges with the documentation and my setup for External Web access. I will admit even after searching the webs and speaking ... I need like F5 or something I read in the setup. Thank you for your time

asked Nov 4 by ckelley (40 points)
0 votes
1 answer

I'm getting a syntax error on this command and I can't figure out what I'm doing wrong: $criteria = New-AdmCriteria "user" {adm-CustomAttributeInt2 -empty $false -and ... AdmCriteria : The criteria is invalid. Syntax error at position 68. At line:1 char:13

asked Oct 17 by jmatthews (190 points)
3,549 questions
3,240 answers
8,232 comments
547,814 users