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

When I enable a scheduled task, instead of running at the scheduled time they all run imeadiately. This is not good behavior as changes are written in a way to reflect the ... is being enabled. I am hoping there is a powershell command to stop this behavoir.

asked Jul 10 by mightycabal (780 points)
0 votes
1 answer

We are implementing the new version of LAPS built into Windows 10 with KB5025221. I've added the attribute to the Management Views for Computers, but the password is not being ... we have not loaded it into AD and plan to use the latest implementation of LAPS.

asked Jul 12 by jshields (20 points)
0 votes
1 answer

Hi team, I need to update users extensionAttribute6 after adding or removing them from a specific group. This is my setup: Group is updated based on rule set within Adaxes ... would like to update users after they were added or removed from this group. Thanks!

asked 4 days ago by wintec01 (440 points)
0 votes
1 answer

I'm trying to modify mailbox settings to add additional email addresses to a user after creation. This is a hybrid on-prem and Exchange Online with E5 licenses. Everything works up ... to a different OU during the process so I know the user exists. Any ideas?

asked Mar 6 by Michael Long (70 points)
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)
3,175 questions
2,878 answers
7,369 comments
507,162 users