Script Repository


Save extension number to attribute of user account

February 24, 2021
1487

The script copies the last digits of a user's telephone number which make the extension number to a certain attribute of the user account. To add the script to your business rules, custom commands and scheduled tasks, use the Run a program or PowerShell script action. For example, see Run PowerShell Script after Creating a User.

Parameters:

  • $phoneExtensionAttribute - Specifies the attribute of user accounts that is used for storing phone extensions.
  • $numberOfDigits - Specifies the number of digits to include in the extension number.
Edit Remove
PowerShell
$phoneExtensionAttribute = "adm-CustomAttributeText1" # TODO: modify me
$numberOfDigits = 4 # TODO: modify me

# Get and check the telephone number
try
{
    $telephoneNumber = $Context.TargetObject.Get("telephoneNumber")
}
catch
{
    # The Telephone Number property is empty
    $Context.LogMessage("Cannot generate an extension number for the user because the user's telephone number is not specified.", "Error") # TODO: modify me
    return
}

# Remove '+' in telephone number
$telephoneNumber = $telephoneNumber.Replace("+","")

# Check telephone number length
if ($telephoneNumber.Length -lt $numberOfDigits)
{
    $Context.LogMessage("Cannot generate an extension number for the user because the user's telephone number ($telephoneNumber) is too short. Minimum 4 digits required.", "Error") # TODO: modify me
    return
}

# Get extension
$extension = $telephoneNumber.SubString($telephoneNumber.Length - $numberOfDigits)

# Save extension to the specified property
$Context.TargetObject.Put($phoneExtensionAttribute, $extension)
$Context.TargetObject.SetInfo()

Comments ( 0 )
No results found.
Leave a comment