# Copying an ADUser

**URL:** https://forums.powershell.org/t/copying-an-aduser/7628
**Category:** PowerShell Help
**Created:** [December 1, 2016, 10:01am UTC](https://forums.powershell.org/t/copying-an-aduser/7628 "2016-12-01T10:01:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 1, 2016, 10:01am UTC](https://forums.powershell.org/t/copying-an-aduser/7628/1 "2016-12-01T10:01:50Z")

</div>

Hello,

I have AD User person6 in AD. I’m trying to create a new AD User called person7 by copying person6

```
$copy = Get-ADUser -Identity person6
New-ADUser person7 -Instance $copy
```

But, it’s giving me an error

New-ADUser : Unknown error (0x21c8)  
At \hqfs1\users\tantony\PowerShell\HRSecurityForms\test.ps1:4 char:1

- New-ADUser person7 -Instance $copy

If this works, does it also copy the new user into the same AD OU as the instance user?

Thank you,

Tony

---

<div class="post-metadata">

### Author: ![jarkko](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jarkko](https://forums.powershell.org/u/jarkko)
#### Post date: [December 1, 2016, 10:16am UTC](https://forums.powershell.org/t/copying-an-aduser/7628/2 "2016-12-01T10:16:35Z")

</div>

Hi

What if you collect all needed parameters and values and use splatting into New-ADUser? I think that would be better solution when copying and creating new AD account.

[https://technet.microsoft.com/en-us/library/gg675931.aspx](https://technet.microsoft.com/en-us/library/gg675931.aspx)

Jake

---

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 1, 2016, 10:26am UTC](https://forums.powershell.org/t/copying-an-aduser/7628/3 "2016-12-01T10:26:01Z")

</div>

I use splatting to create users in branches and it’s working fine, but I’m working on the part where I create users in headquarters. I figured it might be easier to find a person with the same title as the new employee and copy them.

---

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 1, 2016, 11:35am UTC](https://forums.powershell.org/t/copying-an-aduser/7628/4 "2016-12-01T11:35:18Z")

</div>

I figured out to copy a user, and grab info such as the telephoneNumber, Managers etc. I think I had the instance backwards earlier.

```
$u=Get-ADUser -Identity person6 -Properties HomeDirectory, Manager, ProfilePath, Description, Office, telephoneNumber

New-ADUser -Instance $u -SamAccountName person7 –UserPrincipalName person7Reid@mycompany.com –Name 'Person 7' -AccountPassword (ConvertTo-SecureString -AsPlainText "p@ssw0rd" -Force)
```

I want the new user to be in the same OU as the copying user. How would I do that? I tried this below and it didn’t work. It doesn’t move it to the correct DistinguishedName, it creates the new user in the default Users OU. Also, how would I copy the “Member of” to the new user also?

```
$u=Get-ADUser -Identity person6 -Properties HomeDirectory, Manager, ProfilePath, Description, Office, telephoneNumber, DistinguishedName
```

Thanks,

Tony

---

<div class="post-metadata">

### Author: ![jarkko](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jarkko](https://forums.powershell.org/u/jarkko)
#### Post date: [December 1, 2016, 11:57am UTC](https://forums.powershell.org/t/copying-an-aduser/7628/5 "2016-12-01T11:57:11Z")

</div>

Hi

One way to add same groups can be following.

```
$Groups = (Get-ADUser -Identity TestUser2 -Properties Memberof).MemberOF
Add-ADPrincipalGroupMembership -Identity TestUser1 -MemberOf $Groups
```

Or not so readable, I wouldn’t use this on script.

```
Add-ADPrincipalGroupMembership -Identity TestUser1 -MemberOf $((Get-ADUser -Identity TestUser2 -Properties Memberof).memberOF)
```

The same OU, First what comes to mind is to split the DistinguishedName and recreate the Path with that but I do not this that would be the best idea.

Edit. Found following link: [How to get parent container path of the AD user object?](https://social.technet.microsoft.com/Forums/windowsserver/en-US/830ff383-9057-45d8-ae10-5e567efd36f8/how-to-get-parent-container-path-of-the-ad-user-object?forum=winserverpowershell)

Tried this and it was working, result was OU from AD user.

```
Get-ADUser -Identity testuser3 -Properties distinguishedname,cn | 
    select @{n='Path';e={$_.distinguishedname -replace "CN=$($_.cn),",''}} |
        select -ExpandProperty Path
```

Following seems like working.

```
$From = 'person6'
$To = 'person7'

$u = Get-ADUser -Identity $from -Properties HomeDirectory, Manager, ProfilePath, Description, Office, telephoneNumber, memberof, distinguishedName, cn
$Groups = ($u).memberof
$Path = ($u | select @{n='Path';e={$_.distinguishedname -replace "CN=$($_.cn),",''}}).Path

New-ADUser -Instance $u -Path $Path -SamAccountName $To –UserPrincipalName person7Reid@mycompany.com –Name 'Person 7' -AccountPassword (ConvertTo-SecureString -AsPlainText "p@ssw0rd" -Force)

Add-ADPrincipalGroupMembership -Identity $To -MemberOf $Groups
```

Jake

---

<div class="post-metadata">

### Author: ![jefferyhayes](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jefferyhayes/32/265_2.png) [@jefferyhayes](https://forums.powershell.org/u/jefferyhayes)
#### Post date: [December 1, 2016, 12:33pm UTC](https://forums.powershell.org/t/copying-an-aduser/7628/6 "2016-12-01T12:33:17Z")

</div>

I remember this was asked before last year and found the old Bookmark.

[https://powershell.org/forums/topic/copy-ad-user-to-new-one/](https://powershell.org/forums/topic/copy-ad-user-to-new-one/)

---

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 1, 2016, 12:41pm UTC](https://forums.powershell.org/t/copying-an-aduser/7628/7 "2016-12-01T12:41:58Z")

</div>

Thanks all, I’ll try that

---

<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:39pm UTC](https://forums.powershell.org/t/copying-an-aduser/7628/8 "2024-05-16T20:39:58Z")

</div>


