0 votes

Hi there, I am trying creating a report in Adaxes a set of users and looking to add a few group names as column with value 'Yes' or 'No' based on if user is member of that group. below is the example

Name Department Group1
User1 Sales Yes

Adding my current non working script for teh column

$user = $context.GetADObject()

$memeberof = $user.Get("Memberof")

if($memberof.contains("CN=xxx,OU=Security Groups,DC=xxx,DC=xxx")){
$Context.Value = "Yes"
}
else{
$Context.Value = "No"
}

Would appreciate any help in this aspect.

by (120 points)
edited by

1 Answer

0 votes
by (220k points)

Hello,

The main thing here is that you are using the Get method for a multivalued property which will not work. To achieve the desired, use the below script for the custom column generation. In the script, the $groupDN variable specifies the distinguished name (DN) of the group to check. For information on how to get an object DN, see http://adaxes.com/sdk/HowDoI.GetDnOfObject.

$groupDN = "CN=my group,OU=Groups,DC=domain,DC=com" # TODO: modify me

# Bind to the group
$group = $Context.BindToObjectByDN($groupDN)

# Check membership
if($group.IsMember("Adaxes://%distinguishedName%"))
{
    $Context.Value = "Yes"
}
else
{
    $Context.Value = "No"
}
0

Thank you the response.

I tried the above code mentioned, it don't get any error but just the if condition is coming up as true for all the users.

I understand the %distinguishedName% is for adding the parameter,but it looks like this parameter is showing the DN of the user running the report. And thus shows the same value for all the users that come up in the report.

Also what does Adaxes://%distinguishedName% do?

0

Hello,

As we mentioned in the answer, the script should be used in the report custom column. The script will not work anywhere else. In this case, the %distinguishedName% value reference will resolve into the DN of the object being added to the report. image.png If this is not what you need, please, describe the desired behaviour in all the possible details with live examples.

As for Adaxes://%distinguishedName%, it forms the ADS Path of the object.

0

I am using the script as you mentioned exclusively for creating custom column, but the end result is that I am seeing the column value as 'Yes' for users int eh report who are not part of the group.

I tried to see the what is the value in %distinguishedName% as the context value in the if condition as shown below

$groupDN = "CN=my group,OU=Groups,DC=domain,DC=com" # TODO: modify me

# Bind to the group
$group = $Context.BindToObjectByDN($groupDN)

# Check membership
if($group.IsMember("Adaxes://%distinguishedName%"))
{
    $Context.Value = "%distinguishedName%"
}
else
{
    $Context.Value = "No"
}

What is see in the context value is my user DN showing up for all the users in report. I believe this is may be showing the DN for user running the report.

So I tried the below code, but got errors

$GroupDN = "CN=my group,OU=Groups,DC=domain,DC=com"
$User = $Context.GetADObject()
$UserDN = $User.Get("distinguishedName")


# Bind to the group
$group = $Context.BindToObjectByDN($groupDN)

# Check membership
if($group.IsMember("$UserDN"))
{
    $Context.Value = "Yes"
}
else
{
    $Context.Value = "No"
}
+1

Hello,

Sorry for the confusion. You are right, using a value reference will not work in this case. Here is the script that will do the trick.

$groupDN = "CN=my group,OU=Groups,DC=domain,DC=com" # TODO: modify me
# Get object DN
$object = $Context.GetADObject()
$objectDN = $object.Get("distinguishedName")

# Bind to the group
$group = $Context.BindToObjectByDN($groupDN)

# Check membership
if($group.IsMember("Adaxes://$objectDN"))
{
    $Context.Value = "Yes"
}
else
{
    $Context.Value = "No"
}
0

Thank you the above code worked. Would you be able to guide me to a documentation which lists more functions for custom column scripts.

Also I plan to add 10 columns/group check anychance will this affect the perfomance of the report?

0

Hello,

Would you be able to guide me to a documentation which lists more functions for custom column scripts.

Have a look at the following SDK article: http://adaxes.com/sdk/GenerateReportCustomColumns. Also, it is recommended to generate column values in the script generating the report itself. For details, see section Setting values for custom columns of the following SDK article: http://adaxes.com/sdk/GeneratingReports/#setting-values-for-custom-columns.

Also I plan to add 10 columns/group check anychance will this affect the perfomance of the report?

It depends on the number of users to be included into the report. Most probably, it will influence performance.

0

I see so rather than adding the custom columns (script), I create a report based on the Powershell script itself. I actually do have a powershell script which gives me the eaxct report I am trying to build.

Just trying to recreate the report so other team memebrs can check it anytime in Adaxes.

Related questions

0 votes
1 answer

Hello, My question potentially piggy-backs off of the following URL: Automated Expiry of Group Membership We have the need to add/remove users frequently to/from a ... something like this in Adaxes? Thanks in advance for any replies or assistance. Jason

asked Jan 29, 2019 by slowllama (100 points)
0 votes
1 answer

Receive "Index operation failed; the array index evaluated to null. Stack trace: at <ScriptBlock>, <No file>: line 104>" and "Index operation failed; the ... $GroupName, $GroupDN." } } #foreach write-output "" Write-Output "" Stop-Transcript

asked Apr 14 by jbahou (20 points)
0 votes
1 answer

Update group membership based on one property values. I am trying to find a script that resembles "Update group membership based on two property value" but just for one value.

asked Apr 7 by lee_thomas (20 points)
0 votes
1 answer

I am trying to create a process where a user can request access to one or more groups via a web form that also prompts for a date/time to ... = "ADS_SCOPE_SUBTREE" $scopeItem.Exclude = $False $scopeItem.SetInfo() $task.ActivityScopeItems.Add($scopeItem)

asked Apr 15, 2016 by adaxes_user (420 points)
0 votes
1 answer

Hello We are using the script you created for us to upload the employees photo based on their employee ID which works fantastic. The script is below: $picturePath = "picture path" # ... I am missing something obvious but can't see how to do it :? Thank you.

asked Jan 9, 2015 by CBurn (700 points)
2,737 questions
2,471 answers
6,466 comments
1,344,858 users