0 votes

I know this is going to be simple...

We have a script that, when it encounters a user with a blank description field errors out. I've tried to "catch" it as below:-

 foreach ($subordinateDN in $subordinateDNs)  
 {  
 $subordinate = $Context.BindToObjectByDN($subordinateDN)  
 *try  
 {$desc = $Context.$subordinate.Get("description")}  
 catch  
 {$desc = "No Description"}*  
 $htmlReportMiddlePart += "Name: <b>" + $subordinate.Get("name") + "</b> -> " + $desc + "<br>"  
 # Output to GUI execution status report  
 $Context.LogMessage($subordinate.Get("name"), "Information")  
 }  

To try and make this something to do with Adaxes, and not a indicator that my PS skills are poor - is there a general way to deal with attribute queries if they return blank values?

:)

by (1.6k points)

1 Answer

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

Hello,

Actually, using the try...catch block is the correct answer when dealing with empty values, however the statement in the try statement is incorrect. The correct statement will be:
$desc = $subordinate.Get("description")

Also, you get the subordinate's name two times (when generating the report part and when storing a record to the Execution Log). A better option would be to store the subordinate's name in a certain variable and use that variable. The following script block will do the job you need:

foreach ($subordinateDN in $subordinateDNs)
{
    $subordinate = $Context.BindToObjectByDN($subordinateDN)
    try
    {
        $desc = $subordinate.Get("description")
    }
    catch
    {
        $desc = "No Description"
    }
    $subordinateName = $subordinate.Get("name")
    $htmlReportMiddlePart += "Name: <b>" + $subordinateName + "</b> -> " + $desc + "<br>"
    # Output to GUI execution status report
    $Context.LogMessage($subordinateName, "Information")
}
0

Perfect advice as always ;)

Related questions

0 votes
1 answer

I'm using the example from the following SDK page: http://www.adaxes.com/sdk/ManagingSecurityRoles.html # Allow: Reset Password -&gt; User $entry = $role.Permissions.Create() ... from the example. What am I missing here? Thanks for any help you can provide

asked Nov 16, 2015 by drew.tittle (810 points)
0 votes
1 answer

Hi we are trying to add users to a group based on the values of their "Office" and "Description" attributes within Active Directory. We have populated the below ... $Context.LogMessage("No matching criteria found for User $($Context.TargetObject.Name).") }

asked Sep 18, 2023 by Loopy8822 (20 points)
0 votes
0 answers

Before Deactivation of an Account on the Webinterface our Help Desk need to change the AD User Description manually. Is it possible to force a manual change before deactivation ?

asked Feb 7, 2020 by lv01 (20 points)
0 votes
1 answer

Forgive me if this topic has been discussed elsewhere i searched and didn't find anything. What I would like to have adaxes do is on a nightly basis 1. go to a folder it ... disabled by adaxes $date" } Is this possible #4 eludes me a bit. Thank you in advance.

asked Jun 19, 2018 by dexion11 (50 points)
0 votes
1 answer

Hello - I have configured some custom property patterns for office location and Department and am seeing a drop down list when attempting to create a new user limited to the ... down list. Is this therefore only limited to some AD attributes and not others ?

asked Mar 21, 2017 by cdsouza (50 points)
3,548 questions
3,239 answers
8,232 comments
547,814 users