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 = " "
}
# Get user Department
try
{
$userDepartment = $user.Get("department")
}
catch
{
$userDepartment = " "
}
# Get user Employee ID
try
{
$userEmployeeID = $user.Get("employeeID")
}
catch
{
$userEmployeeID = " "
}
# 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