0 votes

I'm trying to update mailNickname to cas_{ but nothing seems to work. This is my completed script of everything working but changing the mailNickname at the end of the code. Any ideas would be helpful. Thanks

Here is the basic code

# Update User mailNickname NOT WORKING
$cas = "cas_{"
$Context.SetModifiedPropertyValue("mailNickname", $cas)
#$Context.SetModifiedPropertyValue("mailNickname", "cas_{") Wont work also

Here is the completed script.

Import-Module Adaxes
$upnSuffix = "YYYYY.com" # TODO: modify me

function IsUserNameUnique($username)
{
   $user = Get-AdmUser $username -erroraction silentlycontinue
   return $user -eq $Null
}

# Get the username
$username = $Context.GetModifiedPropertyValue("samAccountName")

# Check if the username is unique
if (IsUserNameUnique($username))
{
    return
}

# If the username is not unique, generate a unique one
$firstName = $Context.GetModifiedPropertyValue("givenName")
$lastName = $Context.GetModifiedPropertyValue("sn")
$uniqueUsername = $Null
if (($firstName -ne $NULL) -and ($lastName -ne $NULL))
{
    $username = $lastName.Substring(0, 7)
    $Context.LogMessage($username, "Information")
    $Context.LogMessage($lastName, "Information")
    foreach ($char in $firstName.ToCharArray())
    {
        $username = "$username$char"
        if (IsUserNameUnique($username))
        {
            $uniqueUsername = $username
            break
        }
    }
}

if ($uniqueUsername -eq $NULL)
{
    for ($i = 1; $True; $i++)
    {
        $uniqueUsername = $username + $i;
        if (IsUserNameUnique($uniqueUsername))
        {
            break
        }
    }
}

# Update User Logon Name (pre-Windows 2000)
$Context.SetModifiedPropertyValue("samAccountName", $uniqueUsername)

# Update User Logon Name
$Context.SetModifiedPropertyValue("userPrincipalName", "$uniqueUsername@$upnSuffix")
$Context.LogMessage("The username has been changed to " + $uniqueUsername `
    + ".", "Information")

# Update User mailNickname NOT WORKING
$cas = "cas_{"
$Context.SetModifiedPropertyValue("mailNickname", $cas)
#$Context.SetModifiedPropertyValue("mailNickname", "cas_{") Wont work also
by (420 points)
0

Hello,

That's strange. Do you get any errors and/or warnings?

0

I do not get any errors when the account is built.

1 Answer

0 votes
by (420 points)

I got it working. I pulled it from the other script and set up adaxes to run the change command after the username has been checked.

0

Hello,

Thanks for the update!

Related questions

0 votes
1 answer

Are PowerShell commands supposed to show up in the programming interface after adding the module to the Adaxes server? I've installed modules and they don't show.

asked Aug 18, 2020 by ComputerHabit (790 points)
0 votes
0 answers

Hello We added a second domain to our Adaxes environment and we saw a huge drop in performance in the web interface. We are looking at this Web Interface Slow Performance link for now and wanted to see if there were any other suggestions.

asked Feb 21, 2017 by willy-wally (3.2k points)
0 votes
1 answer

HI Support, I'm looking for a business Rule that remove a user from a couple of groups after the User is added to a group. ie 1. The User MaxMi is added to the ... not able to create a powershell scripts for removing the added user from the other Groups. Thx,

asked Jan 4, 2016 by Napoleon (700 points)
0 votes
1 answer

Hi Does the built-in audit feature of Adaxes also track changes NOT made via Adaxes? For example via the usual AD management console? Thanks and best regards! Marius

asked Nov 5, 2021 by PFS_IT (50 points)
0 votes
1 answer

Hello, I'm working on different custom script to integrate Adaxes with custom Cloud Services. The goal will be to trigger Third Part Services directory sync on a ... an external exe that will be replicated by Adaxes automatically accross all Adaxes instances?

asked Sep 29, 2021 by ygini (200 points)
2,756 questions
2,490 answers
6,522 comments
1,458,820 users