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 (272k 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

For instance to execute a powershell script that enable MFA for all member in that group?

asked Jan 27, 2023 by samuel.anim-addo (20 points)
0 votes
1 answer

This note is found in the documentation on how to configure allowed domains in Adaxes 2023. Allowed domain names can only be selected from the alternative UPN suffixes for on- ... required to pick up the change, or is there another way to trigger the update?

asked Jan 31, 2023 by dtb147 (290 points)
0 votes
1 answer

We're utilizing the custom adaxes attributes for a few parts in our employee onboarding procedure. Among them is a step where we specify what buildings a user will need ... get all the values of "adm-CustomAttributeTextMultiValue1" to be sent out in an email?

asked Aug 9, 2021 by KruzGaffaney (50 points)
3,365 questions
3,064 answers
7,815 comments
545,268 users