# Get last created AD account

**URL:** <https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306>\
**Category:** SHF Discussion and Questions\
**Tags:** identity-security-cloud\
**Created:** [May 6, 2025, 1:15pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306 "2025-05-06T13:15:33Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamalika01](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tamalika01/32/14597_2.png) [@tamalika01](https://developer.sailpoint.com/discuss/u/tamalika01)\
**Post date:** [May 6, 2025, 1:15pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/1 "2025-05-06T13:15:33Z")

</div>

Hi Experts,

My problem statement is: get the last created AD account \> get the sAMAccountName from the account and increment it. Is there any way this is possible doing this is the AttributeGenetor Rule?  
Looking for ideas!

Thanks,  
Tamalika

---

<div class="post-metadata">

**Author:** ![sidharth\_tarlapally](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/sidharth_tarlapally/32/26178_2.png) [@sidharth\_tarlapally](https://developer.sailpoint.com/discuss/u/sidharth_tarlapally)\
**Post date:** [May 6, 2025, 2:27pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/2 "2025-05-06T14:27:51Z")

</div>

Hello @tamalika01,

Could you please clarify why we need the `sAMAccountName` of the most recently created account? I’d appreciate it if you could elaborate a bit more on the requirement.

Thanks!

---

<div class="post-metadata">

**Author:** ![ajmerasunny1](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@ajmerasunny1](https://developer.sailpoint.com/discuss/u/ajmerasunny1)\
**Post date:** [May 6, 2025, 5:07pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/3 "2025-05-06T17:07:39Z")

</div>

I’d like to understand your use case better, you could try, suggest creating a delimited source. Whenever you generate a samaccountname, you could write to this delimited source.

Then, you can retrieve the most recently created account from that source and utilize it accordingly

---

<div class="post-metadata">

**Author:** ![iamology](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/iamology/32/6964_2.png) [@iamology](https://developer.sailpoint.com/discuss/u/iamology)\
**Post date:** [May 6, 2025, 5:19pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/4 "2025-05-06T17:19:21Z")

</div>

You might be able to do this using After Creation rule (`type: ConnectorAfterCreate`) where you can run some native PowerShell script to find the last account created (one before the current account that just got created) and extract the number from it, then update the sAMAccountName of newly created AD account

---

<div class="post-metadata">

**Author:** ![UjjwalJain](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ujjwaljain/32/24704_2.png) [@UjjwalJain](https://developer.sailpoint.com/discuss/u/UjjwalJain)\
**Post date:** [May 6, 2025, 5:26pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/5 "2025-05-06T17:26:22Z")

</div>

Hi @tamalika01,

Could you please share a bit more detail about your requirement? That would help us provide a more relevant suggestion.

Thanks,  
Ujjwal

---

<div class="post-metadata">

**Author:** ![Sivakrishna1993](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/sivakrishna1993/32/25424_2.png) [@Sivakrishna1993](https://developer.sailpoint.com/discuss/u/Sivakrishna1993)\
**Post date:** [May 7, 2025, 3:50am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/6 "2025-05-07T03:50:58Z")

</div>

Hi

Do you have multiple AD sources and need to check uniquess then you can follow below LA

> **[How to Search Non-Indexed Account Attributes in IDN Rules for Uniqueness](https://community.sailpoint.com/t5/Identity-Security-Cloud-Wiki/How-to-Search-Non-Indexed-Account-Attributes-in-IDN-Rules-for/ta-p/205863)**
>
> This article will show how to use the recently released feature on creating indexed attributes which can be referenced in rules to do uniqueness searches and generate attributes like sAMAccountName / email / userPrincipalName etc. It allows you to...

---

<div class="post-metadata">

**Author:** ![tamalika01](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tamalika01/32/14597_2.png) [@tamalika01](https://developer.sailpoint.com/discuss/u/tamalika01)\
**Post date:** [June 2, 2025, 2:45pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/7 "2025-06-02T14:45:31Z")

</div>

Hi there, so at the moment we are using an Account Attribute rule ro generate the next sAMAccountName and the logic is as follows:

1. Initialize sAMAccountName = PrefixAAA
2. Check existence \> Does PrefixAAA exist? If no, sAMAccountName = PrefixAAA
3. If yes, increment sAMAccountName = PrefixAAB
4. Check existence \> until sAMAccountName is unique

Now we find that this takes some time to generate as every time in our rule we start with “AAA” and continue till we find a unique value. This is why we are thinking of adding a check. So the new flow could be theretically:

1. Check last created account
2. Get value of sAMAccountName, for eg PrefixDFG
3. Increment sAMAccountName, return next value PrefixDFH

FYI @sidharth_tarlapally @UjjwalJain @Sivakrishna1993

@iamology we don’t want to use a NativeRule for this, as the value of sAMAccountName is not written back automatically after a successful account creation if the scope is outside of ISC. We have already tested this approach and decided to move forward with a Cloud Rule.

---

<div class="post-metadata">

**Author:** ![jesvin90](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jesvin90/32/5301_2.png) [@jesvin90](https://developer.sailpoint.com/discuss/u/jesvin90)\
**Post date:** [June 2, 2025, 4:20pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/8 "2025-06-02T16:20:34Z")

</div>

Hi @tamalika01,

Is prefix value the same for all the users.? If yes, I doubt if you will be able to achieve your use case with ISC, because of the way ISC parallel process each request, independent of the others.

So, if you have 10 account creations on a day, all would be processing almost at the same time and this uniqueness check wouldn’t be possible at all. Which means all would end up with sAMAccountName as PrefixDFG on that day.

---

<div class="post-metadata">

**Author:** ![RAKGDS](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakgds/32/2795_2.png) [@RAKGDS](https://developer.sailpoint.com/discuss/u/RAKGDS)\
**Post date:** [June 2, 2025, 4:41pm UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/9 "2025-06-02T16:41:47Z")

</div>

Hi Tamalika,

Could you please elaborate why you want to do a check again in the Before Provisioning Rule for the requirement you are already able to achieve in the samAccountName Rule ?

Also, i dont think your requirement can be achieved as Sailpoint works on multi threading model where if you get 10 records it will process them the same time and it will be difficult for you to achieve this in Before Provisioning Rule.

Thanks

---

<div class="post-metadata">

**Author:** ![tamalika01](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tamalika01/32/14597_2.png) [@tamalika01](https://developer.sailpoint.com/discuss/u/tamalika01)\
**Post date:** [June 3, 2025, 5:45am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/10 "2025-06-03T05:45:44Z")

</div>

I just checked, i meant AttributeGenerator Rule, apologies for the confusion. I edited my post now.

And as for multi threading, I believe this is applicable for the IdentityAttribute rule where we try to generate a value during an Identity creation/update/refresh which can be multi threaded. But account creation is single threaded and I believe we won’t face this issue when we generate a value during account creation @RAKGDS @jesvin90

So to summarize - we are generating the sAMAccountName in an AttributeGenerator Rule at the moment, which is applied on the “Create profile” in the Source configuration. We did already try our “BeforeCreate” native tule, but the catch was that the new generated values were not written back to ISC after a successful provisioning operation, as all the logic was in the PS script, which was out of scope of ISC.

---

<div class="post-metadata">

**Author:** ![RAKGDS](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakgds/32/2795_2.png) [@RAKGDS](https://developer.sailpoint.com/discuss/u/RAKGDS)\
**Post date:** [June 3, 2025, 9:22am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/11 "2025-06-03T09:22:19Z")

</div>

Hi Tamalika,

So suppose you have 10 accounts that are getting created. Sailpoint wont wait for one account to get provisioned it will start the provisioning of all at once. So if the Create Profile generates a username as AAA111. The other account request wont know that and it might also generate AAA111 as it is still not written in ISC.

---

<div class="post-metadata">

**Author:** ![tamalika01](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tamalika01/32/14597_2.png) [@tamalika01](https://developer.sailpoint.com/discuss/u/tamalika01)\
**Post date:** [June 3, 2025, 9:37am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/12 "2025-06-03T09:37:09Z")

</div>

Are you sure that Create Profile is multi-threaded? I believe accounts get created one by one from a queue. We took this approach as per SailPoint’s best practice recommendation here:

 ![image](https://global.discourse-cdn.com/sailpoint/original/3X/d/9/d96193657cdf3d60537a7bca47f3de540054266a.png)

---

<div class="post-metadata">

**Author:** ![RAKGDS](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakgds/32/2795_2.png) [@RAKGDS](https://developer.sailpoint.com/discuss/u/RAKGDS)\
**Post date:** [June 3, 2025, 9:39am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/13 "2025-06-03T09:39:41Z")

</div>

Yes Tamalika,

We had a similar requirement but the issue was that we were not able to generate unique value but it use to fail if there were 30 - 40 Joiners joining. I would recommend try out in your environment and see if you are seeing some issue if you have 30 - 40 joiners

---

<div class="post-metadata">

**Author:** ![tamalika01](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/tamalika01/32/14597_2.png) [@tamalika01](https://developer.sailpoint.com/discuss/u/tamalika01)\
**Post date:** [June 5, 2025, 6:29am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/14 "2025-06-05T06:29:48Z")

</div>

Thanks for the tipm we’ll test this.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [August 4, 2025, 6:30am UTC](https://developer.sailpoint.com/discuss/t/get-last-created-ad-account/125306/15 "2025-08-04T06:30:17Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
