0 votes

We want to check, if the number of a new team (group) is unique. The number is stored in the attribute "gidNumber". I have a business rule executing before creating group. The following script is executed, but it doesn't check the number. Am i missing something?

Import-Module Adaxes

if ($Context.IsPropertyModified("gidNumber"))
{
    # Get the value
    $value = $Context.GetModifiedPropertyValue("gidNumber")

    # Validate the value
    if (([System.String]::IsNullOrEmpty($value)) -or (-not($value.Contains("-"))))
    {
        $Context.Cancel("Ung├╝ltige Team-Nummer!")
        return
    }

    # Check whether the value is unique
    if ((Get-AdmGroup -Filter 'gidNumber -eq $value') -ne $NULL)
    {
        $Context.Cancel("Ein Team mit dieser Team-Nummer existiert bereits!")
        return
    }
}
by (100 points)
0

Hello,

The script looks just fine. For us to help you with a solution, please, specify the following:

  • Where exactly is the script executed? Is it a Business Rule triggering Before updating a group or Before creating a group? Could you, please, post here or send us (support[at]adaxes.com) a screenshot?
  • What exactly do you mean by it doesn't check the number?
  • Do you face any error messages? If so, please, post here or send us (support[at]adaxes.com) screenshots.
  • Is gidNumber the LDAP name of the property or its display name?
0

The script is in a custom command. I have a business rule triggering before creating a group, which executes the custom command, with scope on all objects

Every team has a number set in the attribute gidNumber image.png

This number has to be unique, no other team should have the same number.

In case a new team (group) is created, the gidNumber of all existing teams must be checked. If the gidNumber of the new team already exists on another team, there should be an error.

Now, the business rule triggers, the script is executed and gives me no error. I can create a team with an existing gidNumber, without an error.

1 Answer

0 votes
by (220k points)

Hello,

To achieve the desired behavior, you need to move the script into the Business Rule triggering Before creating a group. It will never work in a Custom Command. Also, you need to remove the check for dashes being present in the property value as it is an integer property and it cannot have dashes. Find the updated script below.

Import-Module Adaxes

if ($Context.IsPropertyModified("gidNumber"))
{
    # Get the value
    $value = $Context.GetModifiedPropertyValue("gidNumber")

    # Validate the value
    if ([System.String]::IsNullOrEmpty($value))
    {
        $Context.Cancel("Ung├╝ltige Team-Nummer!")
        return
    }

    # Check whether the value is unique
    if ((Get-AdmGroup -Filter 'gidNumber -eq $value') -ne $NULL)
    {
        $Context.Cancel("Ein Team mit dieser Team-Nummer existiert bereits!")
        return
    }
}

Related questions

0 votes
1 answer

Hello, I have a web service that checks if a user is a member of a group. I am not concerned if they are a direct member or an indirect member of a group, but if the user is in the ... I pass it User A and Group 1. I am using ADSI, c# (.Net 4.0), and WCF.

asked Feb 23, 2014 by mbcalvin (140 points)
0 votes
1 answer

Hi, I'd like to implement a rule to ensure that telephoneNumber value is unique accross the domain for each user, either after creation or updates. I tried to implement a ... one (before change). How to get the new value in the script ? Thanks Stephen

asked May 31, 2011 by sroux (800 points)
0 votes
1 answer

So this works for us however we would like to add to check if the last group is at 3 users we would like to send a seperate email but would still like all the above to continue to happen the way it is.

asked Mar 2 by Keonip (160 points)
0 votes
1 answer

Hi, I need to run a schedule task only if a customattribute is not empty. Can I use ConditionIsMet?

asked Oct 7, 2021 by Simone.Vailati (250 points)
0 votes
1 answer

Hello, I want to check if a user is alredy a member of a specific group before doing sometings. This is the piece of code that works well if I execute it on Powershell ... .LogMessage($_.Exception.Message, "Warning") } } So what's wrong?? Thanks in advance!

asked Jun 29, 2016 by tentaal (1.1k points)
2,737 questions
2,471 answers
6,466 comments
1,351,096 users