1. Task runs using an account that has permissions to access all managed users, including this attribute because there's another script that modifies 'terminationDate'. (see attachment)
2. Using GetObject.
3. (&(sAMAccountType=805306368)(employeeID=1*)(!(termFlag=1)))
4. Yes
5. If this excerpt is not sufficient, let me know.
# Process the Business Unit members
try
{
$buResult = $buSearcher.ExecuteSearch()
$objects = $buResult.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
$count = 0
$report = @()
$configurationSetSettingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$admConfigurationSetSettings = $Context.BindToObject($configurationSetSettingsPath)
$connection = New-Object "System.Data.SqlClient.SqlConnection" $connectionString
$connection.Open()
for ($i = 0; $i -lt 10; $i++) #unREM and use this line to try limited user updates or troubleshooting
# for ($i = 0; $i -lt $totalUserCount; $i++)
{ #$Context.LogMessage("i = $i", "Information") #unREM for troubleshooting
# Check whether the user is managed by Adaxes
$userRec = $members.GetObject($i)
$userRec.GetInfo
$userSidsBytes = $userRec.Get("ObjectSid")
$sid = New-Object "Softerra.Adaxes.Adsi.Sid" @($userSidsBytes, 0)
if ($admConfigurationSetSettings.IsUnmanagedAccount($sid))
{
#$Context.LogMessage($userRec.Get("cn") + " is an unmanaged account.", "Information") #unREM for troubleshooting
continue
} else {
# $Context.LogMessage($userRec.Get("cn") + " is a managed account.", "Information") #unREM for troubleshooting
}
#insert function here if it fails getPropertiesFromUserRec
#getPropertiesFromUserRec ($userRec)
[string]$AD_employeeID = $userRec.Get("employeeID")
[string]$AD_givenName = $userRec.Get("givenName")
[string]$AD_sn = $userRec.Get("sn")
# $Context.LogMessage("$i. $AD_givenName $AD_sn" , "Information")
[string]$AD_telephoneNumber = $userRec.telephoneNumber
[string]$AD_mail = $userRec.EmailAddress
if ([System.String]::IsNullOrEmpty($AD_telephoneNumber)){
$AD_telephoneNumber = ""
}
if ([System.String]::IsNullOrEmpty($AD_mail)){
$AD_mail = ""
}
# $Context.LogMessage($AD_mail, "Information") #unREM for troubleshooting
# $Context.LogMessage($AD_telephoneNumber, "Information") #unREM for troubleshooting
try{
$AD_HireDate = $userRec.Get("hireDate")
}catch{
# $Context.LogMessage("No Hire Date", "Information") #unREM for troubleshooting
$AD_HireDate = ""
}
try{
$termDate = $userRec.Get("terminationDate")
$terminationDate = Get-Date -Date $termDate -Format MM-dd-yyyy h:mm
$Context.LogMessage("Actual term $termDate", "Information")
}catch{
$noTermDate = Get-Date -Date "01-01-1900 0:00"
# #$Context.LogMessage("$AD_employeeID has NO term $noTermDate", "Information")
$termDateBody += "$AD_employeeID has NO term $noTermDate `n"
}
if ($terminationDate -ne $noTermDate){
$AD_terminationDate = $terminationDate
} else {
$AD_terminationDate = $noTermDate
}
try{
[string]$AD_wcDeptCode = $userRec.Get("wcDeptCode")
}catch{
# $Context.LogMessage("No dept code.", "Information") #unREM for troubleshooting
$AD_wcDeptCode = ""
}
try{
[string]$AD_wcDivCode = $userRec.Get("wcDivCode")
}catch{
# $Context.LogMessage("No div code", "Information") #unREM for troubleshooting
$AD_wcDivCode = ""
}
try{
[string]$AD_termFlag = $userRec.Get("termFlag")
}catch{
# $Context.LogMessage("No term flag.", "Information") #unREM for troubleshooting
$AD_termFlag = ""
}