Get duplicate users on AD server and append a suffix

I want to append a suffix to differentiate users having same samaccountname.

* Create new AD user
* Get samaccountname of created user($newsam)
* Get list of samaccountname for all users in AD ($allsams)
* Match new samaccountname with list of samaccountname to detect accounts with duplicate samaccountnames
* Append suffix 1 to new user samaccountname and 2,3,4.... as suffixes to others created afterward

Thanks for your help!

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum