Windows Server 2008 R2 enforces a default 20-character limit for local account usernames, which stems from the underlying SAM database architecture. This restriction applies to:
- Local user accounts created via Computer Management
- Accounts created using
net user
command - PowerShell's
New-LocalUser
cmdlet (though this wasn't natively available in 2008 R2)
While Microsoft doesn't officially support modifying this limit, a registry tweak can extend it up to 104 characters:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"MaxUserName"=dword:00000068
Key points about this modification:
- The value is in hexadecimal (0x68 = 104 decimal)
- Requires a system reboot to take effect
- Doesn't affect existing accounts - only new creations
- Maximum practical length is 104 characters due to SAM database constraints
After applying the registry change, verify using these PowerShell commands:
# Check current maximum length setting
(Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa").MaxUserName
# Test account creation with long username
$longName = "ThisIsAVeryLongUsernameThatExceedsStandardLimitsByQuiteABit"
net user $longName /add
Before implementing this change:
- Backup your registry and system state
- Test in non-production environment first
- Be aware some legacy applications may not handle long usernames properly
- Group Policy objects may have their own username length restrictions
If registry modification isn't viable:
- Consider using Active Directory accounts instead
- Implement a naming convention that fits within 20 characters
- Use alias fields or directory attributes to store full names
The 20-character limit dates back to early Windows NT architecture decisions. While newer Windows versions have relaxed this in certain contexts (like Azure AD), the local SAM database in 2008 R2 maintains this legacy restriction.
Windows Server 2008/R2 enforces a default maximum length of 20 characters for local account usernames. This restriction stems from historical compatibility reasons with the SAM database structure. While Microsoft increased this limit to 256 characters in newer Windows versions, Server 2008/R2 remains constrained.
The most reliable method involves modifying the Windows Registry. Create this REG file and execute as Administrator:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SAM\Parameters]
"MaxUserNames"=dword:000000ff
This sets the maximum username length to 255 characters (0xff in hexadecimal). After applying this change, you must restart the server for it to take effect.
To confirm the new limit is active, use this PowerShell snippet:
$maxLength = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SAM\Parameters").MaxUserNames
Write-Host "Current maximum username length: $maxLength characters"
While the registry change allows creating longer usernames programmatically, note that:
- The Server Manager GUI may still truncate at 20 characters
- Some legacy applications might not handle longer usernames properly
- Active Directory integration could be affected
For programmatic account creation with extended usernames, use this VBScript example:
Set objComputer = GetObject("WinNT://" & strComputer & "")
Set objUser = objComputer.Create("user", "ThisIsAVeryLongUsernameExample")
objUser.SetInfo
When implementing this change:
- Document the modification in your server configuration records
- Test all authentication-dependent applications
- Monitor Event Viewer for any SAM-related errors