0 votes

Is it possible to get the pre-modified value for a property, in a PowerShell script in a Business Rule?

e.g., I'm using the Username as a key (I know, not a great idea) in a database table. Now, when the username is modified, I'm not able to get the previous value to use to update the database record, through PowerShell.

by (730 points)

1 Answer

0 votes
by (216k points)

Hello,

It is possible to get the previous value, but only before it was changed. As a workaround, you can use a Business Rule triggered before updating a user. The Business Rule will save the old username to a certain property of the user. For this purpose you can use Adaxes virtual properties that can store text data, for example, CustomAttributeText1. Then, in your Business Rule that updates the database, that is most probably triggered after updating a user, you can access that virtual property to get the previous username.

To get the old username before it is updated, you need to use a PowerShell script. For example, you can use the following PowerShell script that saves the username to a the virtual property called CustomAttributeText1:

$oldUsername = $Context.TargetObject.Get("sAMAccountName")
$Context.TargetObject.Put("adm-CustomAttributeText1", $oldUsername)
$Context.TargetObject.SetInfo()

To be able to run the above script, you need to create a Business Rule triggered Before Updating a User that executes the Run a program or PowerShell script action.

Then, in your script that updates the database, you can access the old username with the following code, for example:

$oldUsername = $Context.TargetObject.Get("adm-CustomAttributeText1")

Related questions

0 votes
1 answer

Let's say I have a Business Rule that is fired prior to adding members to a group. Is it possible to get the number of objects being added to that group as ... that tells me that 6 objects will be added or is each added user treated completely independently?

asked Apr 20, 2022 by ngb (220 points)
0 votes
1 answer

I am wanting to export a list of users including the properties of a specific custom attribute. Ideally, I would be able to run a get-admuser and filter on a custom attribute, but even an excel report with the custom attributes would work. Is this possible?

asked Sep 9, 2021 by ggallaway (300 points)
0 votes
1 answer

I had a business rules that had a PowerShell script to update User properties in a SQL table. It was working fine. I moved the PowerShell to a custom command so I could ... in the custom command does get the values for the User object. Am I missing something?

asked Jun 2, 2014 by sdavidson (730 points)
0 votes
1 answer

We were used to bind to group member object using: $member = $Context.BindToObjectByDN("%member%") which worked perfectly, but now it is not. Its because %member% is returning ... ? And is it possible to get DN of added/removed member using another variable?

asked Sep 14, 2020 by KIT (910 points)
0 votes
1 answer

I read the article on using a business rule to automatically set certain field values such as address based on the value of the Office field. Is there any way to do ... on the Office field so the user has immediate feedback and can change it if necessary.

asked Aug 15, 2016 by jscovill (110 points)
3,351 questions
3,052 answers
7,791 comments
545,091 users