Copy AD user not from template just mirror

I trying to figure out how to copy AD user, most of the scripts I see has to do with making templates to me this is not practical as of now, because I don’t get request to make multiple users maybe just 1 or 2 and they want to mirror a user here mirror a user there. From the pdf I receive they are worded new user James doe, please mirror Jane doe. I would like to just have Get-Aduser bring back the results of firstname lastname I could dig into the GUI to find logon name can’t seem to search for Get-ADuser James doe without errors. I’m doing something like this for another purpose, to retrieve first name and last name, but I don’t want to lookup that information. Maybe it’s easier just to right-click and copy user

$ID = (Get-ADUser -Identity “rtest”).SamAccountName

$fname = (Get-ADUser -Identity “$ID”).GivenName

$lname = (Get-ADUser -Identity “$ID”).Surname

You can use the -Instance parameter of New-ADUser to copy an existing user.

If you require further help with your script, please make sure to use the </> button to format your code.

1 Like

Thanks I’ll check it out, not sure if this is going to solve my issues because I most likely will have to know the users login ID instead of being able to use something like James doe but I’ll l’ll see.

Well you can search AD with:

Get-ADUser -filter "givenName -eq 'John' -and surname -eq 'Doe'"

Obviously no guarantee you’ll get the right user if you have more than one person with the same name. Sounds like a bit of customer education is needed :mortar_board:

1 Like


I believe I can get this working with this

I don’t know if I should create another topic, I believe this is related.
I’m using this: but it errors out with, error below

$MirrorUser = Get-ADUser -filter “givenName -eq ‘Ray’ -and surname -eq ‘Test’”
$MirrorThis = Get-ADUser $MirrorUser -Properties *
New-ADUser -Name ‘Raymond Test’ -Instance $MirrorThis

New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide
At line:3 char:1

  • New-ADUser -Name ‘Raymond Test’ -Instance $MirrorThis
  •   + CategoryInfo          : NotSpecified: (CN=Raymond Test...ate,DC=ca,DC=us:String) [New-ADUser], ADException
      + FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser

As previously requested, please make sure you use the </> button when copying and pasting code.

You can’t use * when copying properties. Not all properties can be copied and, as you’ve found, even those that you’re allowed to copy can cause a problem if they have to be unique. You can override some of the copied properties.

This is not tested as I don’t have VM with AD at the moment, but this is the sort of thing you’re aiming for:

$templateQuery = @{
    Filter     = "givenName -eq 'Ray' -and surname -eq 'Test'"
    Properties = @(

$template = Get-ADuser @templateQuery

$newUserProperties = @{
    Instance          = $template
    Name              = 'Raymond Test'
    SAMAccountName    = 'rtest'
    UserPrincipalName = ''
    AccountPassword   = ('P@ssword' | ConvertTo-SecureString -AsPlainText -Force)
    Enabled           = $true

New-ADUser @newUserProperties
1 Like