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, 2023 by mightycabal (1.0k 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, 2023 by jshields (20 points)
0 votes
1 answer

Hi team, I have a follow up to this question https://www.adaxes.com/questions/14234/business-after-adding-members-powershell-script-executed Let me explain my setup A rule- ... area% failed due to the following exception: $($_.Exception.Message)", "Error") }

asked Feb 13 by wintec01 (1.1k 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 Sep 25, 2023 by wintec01 (1.1k 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, 2023 by Michael Long (70 points)
3,326 questions
3,025 answers
7,723 comments
544,675 users