Hello we want to renaming a user with changing the userhome directory and the exchange properties.
i adding the code we have:
Import-Module Adaxes
function DoesUserExist($username)
{
$obj = Get-AdmUser $username -ErrorAction SilentlyContinue
return $obj -ne $null
}
#first test of username
$username = "%firstname:lower,2%%lastname:lower,2%"
$newValuesAMAccountName = $Context.GetModifiedPropertyValue("sAMAccountName")
$newValuemailNickname = $Context.GetModifiedPropertyValue("mailNickname")
#no entry
$Context.LogMessage("Aktueller sAMAccountName = '$newValuesAMAccountName' und MailNickname = '$newValuemailNickname'.", "Information")
#Check whether an object with the same DN already exists.
if ((DoesUserExist $username))
{
#second test
$username = "%firstname:lower,2%%lastname:lower,3%"
if ((DoesUserExist $username))
{
#third test
$username = "%firstname:lower,3%%lastname:lower,3%"
if ((DoesUserExist $username))
{
#it should work before, if not get this message
$Context.LogMessage("Bitte Namenskürzel prüfen.", "Information")
return
}
else
{
#$Context.LogMessage("Der sAMAccountName wurde auf '$username' gesetzt.", "Information")
$newValuesAMAccountName = $username
$newValuemailNickname = $username
}
}
else
{
#$Context.LogMessage("Der sAMAccountName wurde auf '$username' gesetzt.", "Information")
$newValuesAMAccountName = $username
$newValuemailNickname = $username
}
}
else
{
#$Context.LogMessage("Der sAMAccountName wurde auf '$username' gesetzt.", "Information")
$newValuesAMAccountName = $username
$newValuemailNickname = $username
}
#got the right entries
$Context.LogMessage("Neuer sAMAccountName = '$newValuesAMAccountName' und MailNickname = '$newValuemailNickname'.", "Information")
$Context.SetModifiedPropertyValue("sAMAccountName", $newValuesAMAccountName)
$Context.SetModifiedPropertyValue("mailNickname", $newValuemailNickname)
$newValue = $username
$divValue = "newObj"
#userhome path
$Path = "\\netplans.de\npdfs2\userhome\"
Rename-Item -Path $Path$divValue -NewName $Path$newValue
$Context.LogMessage("New Full Path is $Path$newValue.", "Information")
after this Skript we try to set the new sAMAccountName for:
But the sAMAccountName and Alias for Mail, is ever the old entry. How can we use the new sAMAccountName?