%username% with usernames over 20 characters

These days with the increasing tendency to use double-barrelled surnames resulting in a username that could exceed 20 characters in length, it pays to be careful when setting up accounts for such people.

Suppose we have our usernames in the form firstname.lastname and we have a user “abcdef.ghijkl-mnopqrs”. This username is 21 characters long including the intermediate period. When we create the account, Windows says their pre-Windows 2000 name will be just the first 20 characters. We might then choose to edit the pre-Windows 2000 name to be “abcdef.ghijkl”. But we don’t change the long version of the name which becomes the UPN when added to the UPN suffix (i.e. abcdef.ghijkl-mnopqrs@mydomain.xyz). Windows creates an account in Active Directory. If we copied the account from an existing one, Windows might also automatically create a home directory in the same path as the original account which might be something like \someserverhomesabcdef.ghijkl

This is OK if you are creating one user at a time and copying them. However if you are creating these users from a script, or creating the home directories separately and setting permissions manually, you need to be aware that references to %username% do refer to the pre-Windows 2000 form of the name (the 20 character one). Folder redirection policy will fail if the policy uses the %username% variable to refer to a home folder whose name does not match the pre-Windows 2000 name.