I don't understand how you would use this searcher function. Can you show me in this example?
Import-Module ImportExcel
#set up variables
$currentTime = Get-Date
$Dy = (Get-Date).toString('yyyy-MM-dd')
$startTime = $currentTime.AddDays(-1)
$reportdata = @() #array for all data
$NU = @()
#start with created users
$usersC = Get-ADUser -Filter {(EmployeeType -eq "Employee" -or EmployeeType -eq "Contingent Worker") -and (WhenCreated -ge $startTime)} -Properties *
foreach($User in $usersC){
$UserDN = $User.distinguishedName
$SD = $Context.BindToObjectByDN($UserDN)
Try{
$Boolean6 = $SD.Get("adm-CustomAttributeBoolean6")
}
Catch{
$Boolean6 = $NULL
}
Try{
$date = $SD.Get("adm-CustomAttributeDate2")
}
Catch{
$date = $NULL
}
if ($User.manager) {
$Manager = Get-ADUser -Identity $User.manager -Properties *
$ManagerID = $Manager.employeeID
$ManagerFN = $Manager.givenname
$ManagerLN = $Manager.sn
}
else {
$ManagerID = "Not Available"
$ManagerFN = "Not Available"
$ManagerLN = "Not Available"
}
If($Boolean6 -eq $True){
$UserData = New-Object System.Object
$UserData | Add-Member -membertype Noteproperty -Name 'Log on name' -value $User.SamAccountName
$UserData | Add-Member -membertype Noteproperty -Name 'Employee ID' -value $User.employeeID
$UserData | Add-Member -membertype Noteproperty -Name 'First Name' -value $User.GivenName
$UserData | Add-Member -membertype Noteproperty -Name 'Middle Initial' -value $User.initials
$UserData | Add-Member -membertype Noteproperty -Name 'Last Name' -value $User.sn
$UserData | Add-Member -membertype Noteproperty -Name 'Description' -value $User.description
$UserData | Add-Member -membertype Noteproperty -Name 'Office' -value $User.office
$UserData | Add-Member -membertype Noteproperty -Name 'email' -value $User.mail
$UserData | Add-Member -membertype Noteproperty -Name 'Telephone Number' -value $User.telephonenumber
$UserData | Add-Member -membertype Noteproperty -Name 'Job Title' -value $User.title
$UserData | Add-Member -membertype Noteproperty -Name 'Department' -value $User.Department
$UserData | Add-Member -membertype Noteproperty -Name 'Job Code' -value $User.extensionAttribute3
$UserData | Add-Member -membertype Noteproperty -Name 'Cost Center' -value $User.extensionAttribute9
$UserData | Add-Member -membertype Noteproperty -Name 'Company' -value $User.Company
$UserData | Add-Member -membertype Noteproperty -Name 'Object GUID' -value $User.ObjectGUID
$UserData | Add-Member -membertype Noteproperty -Name 'Manager First Name' -value $ManagerFN
$UserData | Add-Member -membertype Noteproperty -Name 'Manager Last Name' -value $ManagerLN
$UserData | Add-Member -membertype Noteproperty -Name 'Manager ID' -value $ManagerID
$UserData | Add-Member -membertype Noteproperty -Name 'Start Date' -value $date
$reportdata += $UserData
$NU += $UserDN
}
}
if ($reportdata.Count -eq 0) {
# If there are no records to export, create a report with a header stating "No Terminations."
$noNewU = New-Object -TypeName PSObject
$noNewU | Add-Member -membertype Noteproperty -Name 'Message' -value 'No New Users'
$reportdata += $noNewU
$Context.LogMessage("No new Users", "Information")
}
#Export the Data
#Prod Export
$reportdata | Export-Excel -path "D:\EpicReports\EpicReportNewUser$Dy.xlsx" -AutoSize -FreezeTopRow -NoNumberConversion *
#QA Export used for testing
#$reportdata | Export-Excel -path "D:\QA_EpicReports\EpicReportNewUser$Dy.xlsx" -AutoSize -FreezeTopRow -NoNumberConversion *
$Context.LogMessage("Exported data", "Information")
Foreach($NewU in $NU){
$Context.LogMessage("$NewU", "Information")
$U = $Context.BindToObjectByDN($NewU)
$U.Put("adm-CustomAttributeBoolean6", $False)
$U.SetInfo()
}