# Copy AD user not from template just mirror

**URL:** https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842
**Category:** PowerShell Help
**Created:** [March 16, 2022, 5:03pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842 "2022-03-16T17:03:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SaxMan88](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@SaxMan88](https://forums.powershell.org/u/SaxMan88)
#### Post date: [March 16, 2022, 5:03pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/1 "2022-03-16T17:03:57Z")

</div>

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**

---

<div class="post-metadata">

### Author: ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)
#### Post date: [March 16, 2022, 6:26pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/2 "2022-03-16T18:26:06Z")

</div>

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

> **[New-ADUser (ActiveDirectory)](https://docs.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=windowsserver2022-ps)**
>
> Use this topic to help manage Windows and Windows Server technologies with Windows PowerShell.

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

---

<div class="post-metadata">

### Author: ![SaxMan88](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@SaxMan88](https://forums.powershell.org/u/SaxMan88)
#### Post date: [March 16, 2022, 7:33pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/3 "2022-03-16T19:33:26Z")

</div>

> [@matt-bloomfield](#):
>
> New-ADUser

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.

---

<div class="post-metadata">

### Author: ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)
#### Post date: [March 16, 2022, 9:27pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/4 "2022-03-16T21:27:32Z")

</div>

Well you can search AD with:

```auto
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 🎓

---

<div class="post-metadata">

### Author: ![SaxMan88](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@SaxMan88](https://forums.powershell.org/u/SaxMan88)
#### Post date: [March 16, 2022, 9:55pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/5 "2022-03-16T21:55:58Z")

</div>

Thanks

I believe I can get this working with this

---

<div class="post-metadata">

### Author: ![SaxMan88](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@SaxMan88](https://forums.powershell.org/u/SaxMan88)
#### Post date: [March 17, 2022, 5:48pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/6 "2022-03-17T17:48:17Z")

</div>

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
- 

```auto
  + CategoryInfo : NotSpecified: (CN=Raymond Test...ate,DC=ca,DC=us:String) [New-ADUser], ADException
  + FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser
```

---

<div class="post-metadata">

### Author: ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)
#### Post date: [March 17, 2022, 9:09pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/7 "2022-03-17T21:09:47Z")

</div>

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:

```auto
$templateQuery = @{
    Filter = "givenName -eq 'Ray' -and surname -eq 'Test'"
    Properties = @(
        'memberOf'
        'department'
        'company'
        'state'
        'country'
        'city'
    )
}

$template = Get-ADuser @templateQuery

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

New-ADUser @newUserProperties

```

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/copy-ad-user-not-from-template-just-mirror/18842/8 "2024-05-16T20:18:08Z")

</div>


