Hello,
Why is even adm-CustomAttributeObject1 not set? This value is not modified during Powershell Script
As per our tests it worked fine. Please, provide us with a screenshot of the corresponding execution log.
Also, we fixed some coding mistakes in your script. Give the below version a try. It will probably give you more details insight on the actual issue.
. "\\xxxxx\xxxx\xxx\functions.ps1"
## Firstname
$firstname = "%adm-CustomAttributeObject1:format[name],2% Room Mailbox"
$Context.LogMessage("Firstname will be set to: " + $firstname, "Information")
# Update User First Name
$Context.SetModifiedPropertyValue("givenName", $firstname)
## Lastname
$lastname = ReplaceCharacters("%displayName%")
$Context.LogMessage("Lastname will be set to: " + $lastname, "Information")
# Update User Last Name
$Context.SetModifiedPropertyValue("sn", $lastname)
## CN
$Context.LogMessage("CN will be set to: " + $firstname + " " + $lastName, "Information")
# Update User CN
$Context.SetModifiedPropertyValue("cn", $firstname + " " + $lastname)
## Display Name
$displayNamePrefix = "%adm-CustomAttributeObject1:format[name]%"
$displayNamePrefix = $displayNamePrefix.Replace("_"," ")
$Context.LogMessage("Displayname will be set to: $($displayNamePrefix) %displayName%", "Information")
# Update User Display Name
$Context.SetModifiedPropertyValue("displayname", $displayNamePrefix + "%displayName%")
## Username
# Get the username
$username = "%username%"
$Context.LogMessage("Username checking: " + $username, "Information")
# Replace special characters in username
$username = generateSamaccountnameMailbox -mailboxLocation "%adm-CustomAttributeObject1:format[name],2%" -mailboxDisplayname "%displayName%"
$Context.LogMessage("Username updated: " + $username, "Information")
# Update User Logon Name (pre-Windows 2000)
$Context.SetModifiedPropertyValue("samAccountName", $username)
$Context.LogMessage("User Logon Name (pre-Windows 2000): $username", "Information")
# Get domain name
$domainName = "xyz.com"
# Update User Logon Name
$Context.SetModifiedPropertyValue("userPrincipalName", "$username@$domainName")
$Context.LogMessage("User Logon Name: $username@$domainName", "Information")
## Email
# Get the email address
$mail = "%mail%"
# Check if email is set in form
if($mail)
{
$Context.LogMessage("Mail checking: " + $mail, "Information")
# Check if mail is unique
$uniqueEmail = IsEmailAddressUnique -emailaddress $mail
if($uniqueEmail -eq $true)
{
$Context.LogMessage("Mail is unique and can be used", "Information")
$Context.SetModifiedPropertyValue("adm-CustomAttributeText3", $newMail)
}
else
{
$newMail = generateEmailaddress -emailaddress $mail
$Context.LogMessage("Mail is NOT unique and can NOT be used", "Warning")
$Context.LogMessage("New Email Address: " + $newMail, "Information")
$Context.SetModifiedPropertyValue("adm-CustomAttributeText3", $newMail)
}
}
else
{
# No email provided, will generate one
$email = $username + "@" + $domainName
$newMail = generateEmailaddress -emailaddress $email
$Context.LogMessage("Mail not provided, will generate one", "Information")
$Context.LogMessage("New Email Address: " + $newMail, "Information")
# Update User Mail
$Context.SetModifiedPropertyValue("adm-CustomAttributeText3", $newMail)
}
Is it possible to improve warning level like above and add a line number for better reference?
Unfortunately, there is no such possibility.