It was determined that we were one version behind so I just installed the latest Admin. Console (v 3.7.13122.0) and there's still an issue. Here's the requested information.
1. Business Unit Screen Shot:
2. Export Script:
Import-Module Adaxes
# This exports multiple attributes and creates a CSV file minus the Header row.
# Also retrieves the common name for the positionPrimarySupervisor.
# Formats the user name as lastname , firstname middleInitial where possible, otherwise lastname , firstname
$sortBy = "employeeID" # sort search results by UID
$sortDirection = "Ascending" # sort in ascending order
$envir = "1" #Unrem for dev/test
#$envir = "2" #Unrem for production environment, and rem the line above
$businessUnitName = "For Export - Active Users (New)"
try
{
# Read the txt file that has the file export location and field information and then export data
$Context.LogMessage("About to export data to LD Service Desk","Information")
if ($envir -eq "1"){ #if dev/test environment
$filePath = "c:\AdaxesConfigurationFiles\(DEV)DirInt0002_Exp_Info.csv" #Read file from Adaxes c: drive that contain export information
} else { #if production environment
$filePath = "c:\AdaxesConfigurationFiles\DirInt0002_Exp_Info.csv" #Read file from Adaxes c: drive that contain export information
}
# Read the file and put into array variables
$ExpPath = @()
$LDAPNames = @()
$CSVNames = @()
Import-Csv $filePath |`
ForEach-Object {
$ExpPath += $_."ExportPath"
$LDAPNames += $_."LDAPName"
$CSVNames += $_."FieldsOut"
}
if($ExpPath.Length -eq 0)
{
$Context.LogMessage("No export path found. Processing terminated.", "Warning")
return
}
$Context.LogMessage("Export path is: " + $ExpPath, "Information")
$Context.LogMessage("LDAP Names are: " + $LDAPNames, "Information")
$Context.LogMessage("Output Fields: " + $CSVNames, "Information")
# Parse fields
$eachFieldIn = @($LDAPNames[0].split(","))
$eachFieldOut = @($CSVNames[0].split(","))
if (($eachFieldIn.Length -eq 0) -or ($eachFieldOut.Length -eq 0))
{
$Context.LogMessage("Fields missing during import. Processing terminated.", "Warning")
return
}
if (($eachFieldIn.Length) -ne ($eachFieldOut.Length))
{
$Context.LogMessage("Field in/out count mismatch during import. Processing terminated.", "Warning")
return
}
# Build path for the user report file
$exportFile = $ExpPath[0]
# Delete the existing file if it already exists
if (Test-Path $exportFile)
{
Remove-Item $exportFile
}
# Create new file for the user report
New-Item $exportFile -Type File
# Find the Business Unit
$businessUnitsPath = $Context.GetWellKnownContainerPath("BusinessUnits")
$usersearcher = $Context.BindToObject($businessUnitsPath)
$usersearcher.SearchFilter = "(&(objectCategory=adm-BusinessUnit)(name=$businessUnitName))"
$usersearcher.PageSize = 500
$usersearcher.SearchScope = "ADS_SCOPE_SUBTREE"
<#
$userSearcher.SetPropertiesToLoad($eachFieldIn)
$sortOption = New-Object "Softerra.Adaxes.Adsi.AdmSortOption"
$sortOption.PropertyName = $sortBy
$sortOption.Direction = $sortDirection
$userSearcher.Sort = $sortOption
#>
# Get the user information from the search results add them to the file
try
{
$userResult = $userSearcher.ExecuteSearch()
$objects = $userResult.FetchAll()
if ($objects.Length -gt 1)
{
$Context.LogMessage("Found more than one Business Unit with name '$businessUnitName'.", "Warning")
return
}
if ($objects.Length -eq 0)
{
$Context.LogMessage("Business Unit '$businessUnitName' does not exist.", "Error")
return
}
# Get the Business Unit Members
$unit = $Context.BindToObject($objects[0].AdsPath)
$members = $unit.Members()
$totalUserCount = $members.Count
$Context.LogMessage("The total number of users is: " + $totalUserCount, "Information")
$count = 0
$report = @()
for ($i = 0; $i -lt $totalUserCount; $i++)
{
$userRec = $members.GetObject($i)
$reportRecord = New-Object PSObject
foreach ($propertyName in $eachFieldIn)
{
try
{
switch ($propertyName)
{
"positionPrimarySupervisor" {
try {
$managerDN = $userRec.Get($propertyName)
try
{
$supervisor = $Context.BindToObjectByDn($managerDN)
$value = $supervisor.Get("cn")
}
catch
{
$value = ""
}
}
catch {
$value = ""
}
}
"cn" {
# format name as lastname , firstname middleinitial if possible, otherwise as lastname , firstname
$lname = $userRec.Get("sn")
try {
$fname = $userRec.Get("preferredFirstName")
}
catch {
$fname = $userRec.Get("givenName")
}
try {
$mname = $userRec.Get("middleName")
}
catch {
$mname = ""
}
$value = $lname + " , " + $fname + " " + $mname
}
Default {
$value = $userRec.Get($propertyName)
}
} # end switch $propertyName
}
catch
{
$value = "" # The property is empty
}
$reportRecord | Add-Member -Name $propertyName -Value $value -MemberType NoteProperty
} # end foreach propertyname
$report += $reportRecord
$count++
} # end foreach user
}
finally
{
$userResult.Dispose()
}
#$report | Export-Csv $exportFile -NoTypeInformation *** Uncomment this line to export with the Header row
$report | ConvertTo-Csv -NoTypeInformation | select -Skip 1 | Set-Content $exportFile
$Context.LogMessage("Total records exported = " + $count, "Information")
}
catch #catch any unresolved errors
{
$ErrorMessage = $_.Exception.Message
[string]$LineNumber = $_.InvocationInfo.ScriptLineNumber
[string]$Offset = $_.InvocationInfo.OffsetInLine
[string]$errLine = $_.InvocationInfo.Line
Write-Error $ErrorMessage
$Context.LogMessage("At Line #: " + $LineNumber + " at char " + $Offset, "Error")
$Context.LogMessage("Executing: " + $errLine, "Error")
}
-
Membership Rules:
(&(objectCategory=person)(objectClass=user)(!(employeeID=000000))(!(userAccountControl:1.2.840.113556.1.4.803:=2))(!(employeeID=NMU))(!(employeeID=?))(employeeID=*))
-
Although not requested, here's the activity log from the Export scheduled task:
About to export data to LD Service Desk
Export path is: \\data1\isshared\LD ServiceDesk\TEST_LAndesk HR Data Export.csv
LDAP Names are: cn,employeeID,telephoneNumber,positionPrimarySupervisor,positionSupervisorUID,mail,department,division,buildingName,locationFloor,roomNumber,terminationDate
Output Fields: Name,UID,Phone,Manager,Managers UID,Email Address,Dept,Division,Building,Floor,Room,termDate
The total number of users is: 4721
Total records exported = 4721