Hello,
You can use the BuildUsername function provided in our Script Repository: http://www.adaxes.com/script-repository ... y-s191.htm.
The code to use the 1st character of the first name and last 7 characters of the last word in last name would be as follows:
# TODO insert the BuildUsername function from the repository here
# Get last word of surname
$lastnameAsArray = "%lastname%".Split(" ")
$lastWordIndex = $lastnameAsArray.Length - 1
$lastnameLastWord = $($lastnameAsArray[$lastWordIndex]).Trim()
# Build username
$samAccountName = BuildUsername ("%givenName%", 1, "Beginning") ($lastnameLastWord, 7, "End")
# Update samAccountName
$Context.SetModifiedPropertyValue("samAccountName", $samAccountName)
# Update userPrincipalName
$userPrincipalName = $samAccountName + "@" + `
$Context.GetObjectDomain("%distinguishedName%")
$Context.SetModifiedPropertyValue("userPrincipalName", $userPrincipalName)