Default $identity to $sam_account_name if it's set, $name if it isn't #345
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
Fixes an issue where the user's prior existence is checked based on the
name
parameter which is used as the display name of the user.Currently, if both
sam_account_name
andname
parameters are provided but noidentity
parameter is provided during runtime, the user will be created but later will cause errors since theNew-ADUser
cmdlet runs when the user already exists, causing anADException
. This is because theGet-ADUser
cmdlet is run with theidentity
parameter set as it's-Identity
parameter.identity
defaults to thename
parameter which would equate to the user's display name.The current
New-ADUser
cmdlet creates users with theName
of the user as theSamAccountName
andName
Property of the user. If you pass a separateSamAccountName
property, theName
parameter is instead only set to the givenName
parameter.Here's an example showing how the PowerShell process works currently:
The fix sets the
identity
module parameter to thesam_account_name
provided preferentially, otherwise thename
is used. This should mean that users updating the collection will be unaffected since if they were using just the name previously, the handling of the rest of the module is exactly the same.Fixes #344
ISSUE TYPE
COMPONENT NAME
community.windows/win_domain_user