Closed nicovs closed 1 year ago
Everything I've read online indicates the maximum limit is 20 characters as the local SAM database enforces that. The Win32 C API that can create a user even explicitly calls this out https://learn.microsoft.com/en-us/windows/win32/api/lmaccess/nf-lmaccess-netuseradd?redirectedfrom=MSDN
User account names are limited to 20 characters
If you do find a method that works I'm happy to investigate it further but until then there's nothing I can do.
hi @jborean93 , you are right, according to https://learn.microsoft.com/en-us/troubleshoot/windows-server/identity/net-add-not-support-names-exceeding-20-characters we can use workarounds with vbs or watever... i'll look into it.
hey @jborean93 , thought i'd share it here to help other people if needed. Fixed this issue using win_dec:
- name: "Create user {{ username }}"
ansible.windows.win_dsc:
resource_name: User
Ensure: "Present}"
Disabled: "false"
UserName: "{{ username }}"
Description: "user for {{ username }}"
Password_password: "{{ userpasswd }}"
PasswordNeverExpires: true
DependsOn: "[group]IIS_IUSRS"
I could not get this working
Failed to invoke DSC Set method: PowerShell DSC resource MSFT_UserResource failed to execute Set-TargetResource functionality with error message: There could be a possible multiple matches exception while trying to use the System.DirectoryServices API's.Exception calling "Save" with "0" argument(s): "The specified username is invalid.
SUMMARY
Creating a Windows user using win_user with a username length > 20 characters fails, although this is perfectly possible to create it manually. According to the docs, max user length should be 256 characters: https://learn.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-autologon-username
The issue is probably related to: https://github.com/ansible-collections/community.windows/issues/281
ISSUE TYPE
COMPONENT NAME
ansible.windows.win_user
ANSIBLE VERSION
(but also other versions)
COLLECTION VERSION
OS / ENVIRONMENT
Creating local users on Windows Server 2019 (so not AD users)
STEPS TO REPRODUCE
replace the username with anything longer than 20 characters
EXPECTED RESULTS
User should be created without a problem.
ACTUAL RESULTS
The user does not get created, but fails with an error that the username is invalid