0 votes

Hi,
Was wondering if there's a nice way to manually or automatically check if a username or an extension is in use before creating a user?

What do other people do? If there wasn't a nice way, I was thinking it might just be OK to follow the process of seeing an error in the results, deleting the user and starting again - but would rather the checks first.

by (710 points)

1 Answer

0 votes
by (214k points)
selected by
Best answer

Hello Adam,

You can check whether the username is unique using a PowerShell script. If it is not unique, you can, for example, automatically add a digit to the end of the username. To learn how to do that, refer to the following tutorial: http://www.adaxes.com/tutorials_Simplif ... Script.htm. On Step 5, see Example 2.

If you prefer cancelling creation of a new user instead of adding a digit, that can also be done. For this purpose, use the following version of the script:

Import-Module Adaxes

$username = $Context.GetModifiedPropertyValue("samAccountName")

function IsUserNameUnique($username)
{
   $user = Get-AdmUser $username -erroraction silentlycontinue
   return $user -eq $Null
}
if (-not(IsUserNameUnique($username)))
{
    $Context.Cancel("The username is not unique.")
}

As for the extension, do you specify it using a certain property of the user account? If you do, you can use the same approach to check extensions specified for new users.

0

That's great thanks - I'm not sure what to replace $username with for the phone, as the options shown when pressing '$' don't relate to telephone. Can I call that field somehow to check?

0

Hello Adam,

Sure, here you are:

Import-Module Adaxes

function IsTelephoneNumberUnique($telephoneNumber)
{
   $user = Get-AdmUser -Filter 'telephoneNumber -eq $telephoneNumber' -erroraction silentlycontinue
   return $user -eq $Null
}

# Get the telephone number
$telephoneNumber = $Context.GetModifiedPropertyValue("telephoneNumber")

# Check if the telephone number is unique
if (-not(IsTelephoneNumberUnique($telephoneNumber)))
{
    $Context.Cancel("The telephone number is already in use")
}
0

Thanks, looks like the telephone is working but for the username one I get this error:

Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and try the command again.

This is the script, just copied/pasted:

Import-Module Adaxes
function IsUserNameUnique($username)
{
   $user = Get-AdmUser $username -erroraction silentlycontinue
   return $user -eq $Null
}
if (-not(IsUserNameUnique($username)))
{
    $Context.Cancel("The username is not unique.")
}
0

Hello Adam,

Sorry, there was a line missing. Here's the correct version of the script:

Import-Module Adaxes

$username = $Context.GetModifiedPropertyValue("samAccountName")

function IsUserNameUnique($username)
{
   $user = Get-AdmUser $username -erroraction silentlycontinue
   return $user -eq $Null
}
if (-not(IsUserNameUnique($username)))
{
    $Context.Cancel("The username is not unique.")
}
0

Thanks - tested and works perfectly now :)

0

Thanks! I was about to report this as well, but it now works perfectly!

Related questions

0 votes
1 answer

Hi Team, We are using a set of form/business rules/custom commands for user creation that move user account to the right OU given the Office attribute value. I would ... , but can't find valuable information on the web site. Thanks in advance Regards Stephen

asked Dec 12, 2012 by sroux (7k points)
0 votes
1 answer

All, I was wondering if there is a way to add check boxes that correspond to custom commands. Ie if I as the administrator want to give another user the ability to create ... to specific groups. All this would be avaliable from the new user form. Thanks, Tony

asked Nov 5, 2015 by cyspry (2.7k points)
0 votes
1 answer

I have a word document that I need to have the users first and last name added to along with the password. I was wondering if you know of an easy way to capture ... variables and pass them to a word document via a Custom Command or Business rule. Thanks, Tony

asked Sep 21, 2015 by cyspry (2.7k points)
0 votes
1 answer

Hi folks, I am looking for suggestions on the best way to create/migrate/remote move our student mailboxes to 365. Until now, I have been creating the new AD accounts and ... a 'remote mailbox' in the contacts container. Let the magic begin.... Thanks Kempy

asked Jan 7, 2015 by ckemp (940 points)
0 votes
1 answer

We were wondering if Adaxes has a script available to create AS400 accounts during the AD creation. This will allow us to totally automate the new hire process going forward.

asked Jan 26, 2017 by willy-wally (14.5k points)
2,135 questions
1,900 answers
5,319 comments
3,531 users