'how to create a user based on an account that already exists
I would like to validate by displayname if the user has an 'A0' account in the OU OU=Users,OU=A0,DC=DomainA,DC=com.
If the user has an 'A0' account please create his 'A1' account with the same last five digits of his A0 account. Can you help me with this?
Get-Aduser -filter {(displayname -like "Tremblay,*")} -SearchBase "OU=Users,OU=A0,DC=DomainA,DC=com" -properties surname, givenname, samaccountname, userprincipalname, name | select surname, givenname, samaccountname, userprincipalname, name
#Result --- The user has a (A0-XXXXX) samaccountname: A0-25000
#Please create his A1 account with the same last five digits of his A0 account ---- should be like this: A1-25000
$OU = "OU=Users,OU=A1,DC=DomainA,DC=com"
$Password = "JmFdMdptbrnk!1022$"
New-ADUser -GivenName $givenname -Surname $surname -displayname $displayname -SamAccountName $Username -UserPrincipalName $UserPrincipalName -Name $Name -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -ChangePasswordAtLogon $False -Enabled $true -Path $OU
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
