This topic contains 5 replies, has 3 voices, and was last updated by
July 8, 2015 at 9:41 am #27308
I need to figure something and I think I miss it.
In the AD Users and Computer mmc, you can do a right click on a user and select Copy. This will create a new user with some information from the source user.
I tried to figure, how I can do that with PowerShell ?
I tried this :
New-ADUser -SamAccountName testps2 -AccountPassword (Read-Host "Password" -AsSecureString) -Instance testps
But this creates the user, but it's blank. So I think my -Instance not worked. This I miss something.
July 8, 2015 at 9:47 am #27309KeymasterPoints: 1,811Rank: Community Hero
The help for New-ADUser actually covers this. For example:
Method 2: Use a template to create the new object. To do this, create a new user object or retrieve a copy of an existing user object and set the Instance parameter to this object. The object provided to the Instance parameter is used as a template for the new object. You can override property values from the template by setting cmdlet parameters. For examples and more information, see the Instance parameter description for this cmdlet.
So you'd use Get-ADUser to get the source user into a variable, and then pass that to the -Instance parameter of New-ADUser.
The help covers other techniques as well, and provides some examples.
July 8, 2015 at 9:48 am #27310ParticipantPoints: 0Rank: Member
Use the -Instance parameter on New-AdUser to specify a user account to copy. You'll need to specify the properties you want to copy and you CAN'T use * as you'll attempt to copy the SID and get an error.
I cover this in detail in chapter 2 of Learn AD management in a month of Lunches – http://www.manning.com/siddaway3/
July 8, 2015 at 10:00 am #27312
Thanks for the answers.
Tried this :
$t = Get-ADUser testps New-ADUser -SamAccountName testps2 -AccountPassword (Read-Host "Password" -AsSecureString) -Instance $t
But this gives me a weird result. The new user has the same User logon name of the source user. Only the User logon name (pre-Windows 2000) as changed.
And nothing follows, not the telephone, the fax, the group membership, etc.
Did I need to put in variables each value I want from source to push it to the new user ?
July 9, 2015 at 12:56 am #27330ParticipantPoints: 0Rank: Member
Yes – you are using the old user account as a template so all properties you retrieve for the old account will be copied across. Using a template like this is mot use where you have a set of properties – often group memberships & organization related properties – that you want to duplicate.
You have to set all other properties on the new account – especially the name related properties
July 10, 2015 at 5:12 am #27384
I started to figure how I will do it.
Have a great day.
The topic ‘Copy AD user to new one.’ is closed to new replies.