0 votes

Hi,

is it possible to use adm-CustomAttributeText with .SearchFilter?

I need to create a new scripted report based on an older one I have but it seems like the $searcher is not working.
Here's what I have so far

$searcher = $Context.TargetObject
$searcher.PageSize = 500
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SearchFilter = "(adm-CustomAttributeText12=$name)"
$searcher.SetPropertiesToLoad(@("userPrincipalName","cn","description","mobile","telephoneNumber","accountexpires","manager","adm-CustomAttributeText12"))

$searchResult = $searcher.ExecuteSearch()

foreach ($userID in $searchResult.FetchAll()) {
  #generate report and send by mail
}

Once executed no results are returned even so $name contains a valid value
for completion here's the whole code I'm using right now

function sendReport ($name) {

# Search all users in the target object
$searcher = $Context.TargetObject
$searcher.PageSize = 500
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SearchFilter = "(adm-CustomAttributeText12=$name)"
$searcher.SetPropertiesToLoad(@("userPrincipalName","cn","description","mobile","telephoneNumber","accountexpires","manager","adm-CustomAttributeText12"))

# Email message settings
$to = "$name" #$name contains a email address
$subject = "List of the users for $name" 

$searchResult = $searcher.ExecuteSearch()

$htmlBuilder = New-Object "System.Text.StringBuilder"
$htmlBuilder.append("<html><head>")
$htmlBuilder.append("<style type=""text/css"">
table.myTable { 
  border-collapse: collapse; 
  }
table.myTable td {
border: 1px solid black;
padding: 5px;
background-color: white;
font-size: 11px;
font-family: Arial;
} 
table.myTable th { 
  border: 1px solid black;
  padding: 5px;
  background-color: #CCCCCC;
  font-size: 12px;
font-family: Arial; 
  }
</style>")
$htmlBuilder.append("<meta http-equiv=""Content-Type""`
    content=""text/html charset=UTF-8""></head>")
$htmlBuilder.append("<body>")
$htmlBuilder.appendFormat(
    "<p>Users in lfext.com (<b>{0}</b>)</p>",
    $searchResult.count)
$htmlBuilder.append("<table class=""myTable""")
$htmlBuilder.append("<tr>")
$htmlBuilder.append("<th>User Name</th>
    <th>Company</th><th>Title</th><th>Email</th><th>Phone</th><th>Mobile</th><th>LF Contact</th><th>LF Title</th><th>LF Mail</th><th>Expiration Date</th><th>Reason for Disable</th><th>Created</th><th>Modified</th><th>Status</th>")
$htmlBuilder.append("</tr>")

foreach ($userID in $searchResult.FetchAll()) {

        $user = $Context.BindToObject($userID.AdsPath)

        $currentDate = Get-Date
        $accountExpires = $user.Get("accountExpires")

        if ($user.AccountDisabled) 
        {

            $htmlBuilder.append("<tr>")       
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["cn"].Value)       
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("company"))       
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("title")) 
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("mail"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["telephoneNumber"].Value)
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["mobile"].Value)
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText10"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText11"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText12"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.AccountExpirationDate)
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["description"].Value)  
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("createTimeStamp"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("modifyTimeStamp"))
            $htmlBuilder.appendFormat("<td>disabled</td>") 
            $htmlBuilder.append("</tr>")   

        } elseif (($user.AccountExpirationDate -lt $currentDate) -and ($accountExpires -ne 0) -and ($accountExpires -ne 9223372036854775807))
        {
            $htmlBuilder.append("<tr>")       
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["cn"].Value)       
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("company"))       
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("title")) 
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("mail"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["telephoneNumber"].Value)
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["mobile"].Value)
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText10"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText11"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText12"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.AccountExpirationDate)
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["description"].Value)  
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("createTimeStamp"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("modifyTimeStamp"))
            $htmlBuilder.appendFormat("<td>expired</td>") 
            $htmlBuilder.append("</tr>")
        } else
        {
            $htmlBuilder.append("<tr>")       
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["cn"].Value)       
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("company"))       
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("title")) 
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("mail"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["telephoneNumber"].Value)
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["mobile"].Value)
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText10"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText11"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("adm-CustomAttributeText12"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.AccountExpirationDate)
            $htmlBuilder.appendFormat("<td>{0}</td>", $userID.Properties["description"].Value)  
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("createTimeStamp"))
            $htmlBuilder.appendFormat("<td>{0}</td>", $user.Get("modifyTimeStamp"))
            $htmlBuilder.appendFormat("<td>active</td>") 
            $htmlBuilder.append("</tr>")
        }
}

$htmlBuilder.append("</table>")
$htmlBuilder.append("</body></html>")
$Context.SendMail($to, $subject, $NULL,
    $htmlBuilder.ToString())

}

Any help would be appreciated!

kind regards
Ingemar

by (960 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello Ingemar,

The issue Search using custom boolean attribute not returning results on the forum. Your search query does not return any results because currently Adaxes custom attributes are not included in LDAP searches for performance considerations. To work around the issue, in your task, you can bind to each user one-by-one and check the value of the attribute. In our Script Repository, we have a script that does a very similar job: creates an HTML-formatted list of users who have a certain custom attribute assigned (not empty). See it here: http://www.adaxes.com/script-repository ... ty-s43.htm. You can use it as a starting point.

Related questions

0 votes
1 answer

We have some users who work offsite and rarely authenticate to our local domain controllers but they frequently log into our M365/Entra environment. Will the adm-InactivityDuration ... to check if they are inactive in both local AD and Entra before proceeding?

asked Nov 4 by smcfarland (60 points)
+1 vote
1 answer

When building a form, is there a way I can request the user to answer questions? I understand there is the adm-customattributes that aren't stored in AD, but I don' ... the reason why, rather than just seeing "What" change is being requested. Thank You!

asked Mar 1, 2023 by Edogstraus00 (490 points)
0 votes
1 answer

Hello, We are currently allowing users to submit requests for new user accounts within the domain. By default, the logon name is being formatted as %firstname%.%lastname% However this ... pre-Windows-2000 user logon name. Is there a way to work around this?

asked Dec 11, 2020 by sirslimjim (480 points)
0 votes
0 answers

Hey Guys We have some issues with new meeting rooms that we have created. Previously we used to have on-premise exchange but switched to office365. Before doing ... OU but the interface are different. under exchange properties they are different aswell.

asked Sep 18, 2019 by seanr (70 points)
0 votes
1 answer

Hi, I'm looking at automatically creating mailboxes when new users are created, We have a large amount of users with the same name (as accounts are based on first ... already exists in exchange and add a prefix to the address before completion? Regards Thomas

asked Mar 26, 2013 by cunningham57906 (40 points)
3,589 questions
3,278 answers
8,303 comments
548,105 users