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