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

Hi All, I am currently using the 30 day free trial of Adaxes and seeing if we can use it to achieve our method of user provisioning. I am looking into server-side ... variable value within an SQL query Can this be achieved? Any help is much appreciated, Thanks

asked Feb 1 by Lewis (40 points)
0 votes
1 answer

Let's say I have a Business Rule that is fired prior to adding members to a group. Is it possible to get the number of objects being added to that group as ... that tells me that 6 objects will be added or is each added user treated completely independently?

asked Apr 20, 2022 by ngb (220 points)
3,351 questions
3,052 answers
7,791 comments
545,091 users