0 votes

Hi,

Is there any native way to auto-increment a custom interger attribute?

I know I can use a PS script, but just wondering whether there is a quick way to use an Adaxes action i.e. "CustomAttributeInt1 = CustomAttributeInt1+1"

Thanks

by (1.6k points)
0

Hello,

This can be done with a PowerShell script. Our script guys can write you a sample, but to do this, we need to know what should happen if the property is empty (i.e. not specified)? Should an empty property be considered a 0 and the script will just set it to one, or should the script produce an error/warning/information message?

0

Mmm, interesting question!

As far as my current use case - the value should never be empty, in that this attribute is set when a user account is created, or when it has been renewed (the attribute is to carry the number of days past the annual review date the account is, and is reset to 0 when successfully renewed).

However, this does touch on some of the logic I'm actually using this for, in that I'm trying to catch any condition that my workflows may encounter due to unforseen circumstances.

Core example is, if my workflows expect an 'account review cycle' to be triggered on the review due day, but we had a power-down on that day so the daily scheduled task didn't execute, what happens on the next day? If we allow our job to trigger on past dates to 'catch up' there is a risk that we may re-execute the job in error, so I'm looking at this attribute to be a 'safety check' i.e. "IF Review date in past AND Counter > 0 THEN "Review Task" has already initiated so Cancel".

We can also use this to trigger specific reminders i.e. send gentle email after 7 and 14 days, but start getting "shouty" after 21, and scream on days 26, 27 and 28 without constantly performing date checks (or making the date comparison another safety check)!

So, in this case, I think we can assume empty is == 0, but something else to ponder for me!

Rgds

1 Answer

0 votes
by (216k points)

Hello,

As to your 'account review lifecycle', proceeding from one of your General advice re: ordering actions, you already use a certain property called Account Status, and you set it to Under Review before submitting an approval, and revert it back when successfully approved. Your Scheduled Task triggers only when Account Status is not set to Under Review for the user, which is, to our mind, quite enough to make it a fail-proof solution. The value of the Account Status will always identify whether the 'Review Task' has already been initiated on the user.

If you still insist on incrementing an integer value, here's a PowerShell script that does the job:

$propertyName = "adm-CustomAttributeInt1" # TODO: Modify me

try
{
    $value = $Context.TargetObject.Get($propertyName)
}
catch
{
    $value = 0
}
$value++
$Context.TargetObject.Put($propertyName, $value)
$Context.TargetObject.SetInfo()

In the script, $propertyName specifies the name of the attribute that you use, for example, CustomAttributeInt1. Modify the script to your requirements.

You can use the Run a program or PowerShell script action to use the PowerShell script in an existing Scheduled Task or create a new Task that executes the script.

0

Many thanks.

I agree that the "Account Status" (actually we're tweaking the logic somewhat to use the "Review Status" as the marker) should be enough to prevent against re-execution.

Related questions

0 votes
1 answer

Hi, One of our requirement is to automaticaly generate computer names, in a incremental way. For instance Computer0001 Computer0002 Computer0003 I was unable to do that with ... following error: Name is not specified for the new object Any idea is welcome.

asked Mar 19, 2013 by Pierre (750 points)
0 votes
1 answer

Is it possible to script having users added (or removed) from a Security Group based on another AD Attribute? I have found ways to do this in Powershell (something like): ... just utilize the PS script and just run it through Adaxes on a timed fashion? Thanks!

asked Oct 7, 2014 by PunkinDonuts (360 points)
0 votes
1 answer

Hi - random PowerShell question (I do seem to ask more PowerShell questions than Adaxes questions...!). We have a little bit of code to return the current value of an AD attribute ... ;", $newNums) $pc.SetInfo() Anyone who can work this out is my hero..! Rgds

asked Jun 8, 2016 by firegoblin (1.6k points)
0 votes
1 answer

Is it possible to create a business unit and have it auto populate with group owners in a specific OU. I've tried a few scripts to get propertie adm-managedbylist but none have worked so far.

asked Nov 18 by C27 (20 points)
0 votes
1 answer

I am trying to have a scheduled job that will hide groups that are empty and I can not seem to figure out how to do it.

asked Aug 20, 2021 by hgletifer (1.3k points)
3,588 questions
3,277 answers
8,303 comments
548,090 users