0 votes

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()
}
by (1.0k points)
0

Hello,

Sorry for the confusion, but we are not sure what exactly you need to finally achieve. Please, describe the desired behavior in all the possible details with live examples.

0

You stated that I can't use get-admuser to collect all the users with a customAttributeBoolean6 in a variable named $usersC and pointed me to some function that makes no sense to me. I am asking you to show me how you would use the searcher function you pointed me to in this script so that all the users who have a customattributeboolean6 in the $usersC variable.

1 Answer

0 votes
by (288k points)

Hello,

In the script we referenced, there is a search performed. The basic criteria is only for users as Adaxes custom attributes cannot be included. After the search is executed, method $searchResult.FetchAll() returns search results for all the users found. You can then iterate through the results and bind to the corresponding users. If you face issues writing the full script (seems like you just need to keep the users in certain groups), please, describe the exact desired behavior in details with examples and we will do our best to help you.

Related questions

0 votes
1 answer

Trying to set the primary proxy when doing a name change on an email address.

asked Jul 13, 2023 by mightycabal (1.0k points)
0 votes
1 answer

Occationally Service Desk staff need to clear a DNS record when a desktop has been reimaged but is keeping the same name as loses the ability to manage its original DNS ... running in ADAXES. Can I just install the applet on the ADAXES server using powershell?

asked Jan 17, 2023 by stevehalvorson (110 points)
0 votes
1 answer

Hi, would it be possible to script a workstation in AD and also directly from our local SCCM environment ?

asked Oct 28 by ddesmedt (40 points)
0 votes
1 answer

The rule runs but since the first name and last name are passed as parameters, I only get the sequential # as a userID without the initials.

asked Oct 24 by curtisa (290 points)
0 votes
1 answer

We try to use ADSI scripting to automate some tasks using Adaxes 2023. One such task is to try to check whether an answer provided by a user to his question is correct or not. ... . But I do not see an easy way to do this using ADSI script and/or interfaces.

asked Oct 22 by gfang (20 points)
3,537 questions
3,227 answers
8,219 comments
547,727 users