Trying to get help on the error here<\/p>\n
$MirrorUser = Get-ADUser -filter “givenName -eq ‘Ray’ -and surname -eq ‘Test’”
\n$MirrorThis = Get-ADUser $MirrorUser -Properties *
\nNew-ADUser -Name ‘Raymond Test’ -Instance $MirrorThis<\/p>\n
Error below<\/p>\n
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide<\/p>\n
At line:3 char:1<\/p>\n
New-ADUser -Name ‘Raymond Test’ -Instance $MirrorThis<\/p>\n
Here you go, just edit as needed:\n\n<#\nThis will copy a user and then set the new users info for new hires. \n#>\n\n#Import module\nImport-Module activedirectory\n\n# Section for you to define your variables\n\n#Set new users info here:\n$firstname = 'Eric'\n$lastname = 'Short'\n$title = \"janitor\"\n\n#set old user account here that you are copying:\n$olduser = \"usernamehere\"\n\n#Set the new user AD account (example: rstimpy):\n$newuser = \"rstimpy\"\n\n#Path to the OU where they're account is being placed:\n$path='OU=users,DC=domain,DC=com'\n\n#prompts for you to set their PW:\n$password = Read-Host -Prompt \"Set New Users Password\" -AsSecureString\n\n#Copies user based of old user attributes:\n$userinstance = Get-ADUser -Identity $olduser -Properties Title,Office,Manager,Description,Department,Office\n\n# Create a new user account\nNew-ADUser -SAMAccountName $newuser -Instance $userinstance -DisplayName \"$firstname $lastname\" -GivenName $firstname -Name \"$firstname $lastname\" -Surname $lastname -UserPrincipalName ($firstname+\".\"+$lastname+\"@intervala.com\") -AccountPassword $password -ChangePasswordAtLogon $true -Enabled $true -path $path \n\nWrite-Host \"Creating new user account $newuser\" -Foreground Green\nStart-Sleep -Seconds 10\n\n#Copies old user groups to new user account:\nGet-ADUser -Identity $olduser -Properties Memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $newuser\n\nWrite-Host \"Importing Groups from $olduser to $newuser\" -Foreground Green\nStart-Sleep -Seconds 10\n\nSet-ADUser -Identity $newuser -Enabled $true\nSet-ADUser -Identity $newuser -DisplayName \"$firstname $lastname\" -StreetAddress \"1 Tech Dr., Suite 1\" -City \"Pleasant\" -State \"MA\" -PostalCode \"11111\" -Office \"mainoffice\" -OfficePhone \"999-999-9999\" -Country \"US\"\nSet-ADUser -Identity $newuser -Description \"$title\" -EmailAddress ($firstname+\".\"+$lastname+\"@domain.com\") -ScriptPath \"logon.bat\"\nSet-ADUser -Identity $newuser -Title \"$title\"\nSet-ADUser -Identity $newuser -add @{ProxyAddresses=(\"SMTP:\"+$firstname+\".\"+$lastname+\"@idomain.com\")}\nSet-ADUser -Identity $newuser -Company \"workplace\"\n\nNew-Item -Path $upath -ItemType Directory\nNew-Item -Path $upath2 -ItemType Directory\nWrite-Host \"Scan folder created at: $upath for users: $newuser\" -Foreground Green\nStart-Sleep -Seconds 3\n\n#Sets Permissions\n$acl = Get-Acl -Path $upath\n$permission = $newuser, 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'\n$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission\n$acl.SetAccessRule($rule)\n$acl | Set-Acl -Path $upath\nWrite-Host \"Setting ACL Permissions for $newuser. Please Wait...\" -Foreground Green\nStart-Sleep -Seconds 60\n\n#AD Sync\nInvoke-Command -ComputerName \"DC-Server-Here\" -ScriptBlock {Start-ADSyncSyncCycle -PolicyType delta} \nWrite-Host \"Syncing AD. Please Wait...\" -Foreground Green\nStart-Sleep -Seconds 10\n\nWrite-Host \"New AD user: $newuser has been created, tasks completed. Have a good day!\" -Foreground Green\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2022-03-17T18:21:34.000Z","url":"https://community.spiceworks.com/t/copying-user-powershell/828037/4","author":{"@type":"Person","name":"andytechacct","url":"https://community.spiceworks.com/u/andytechacct"}},"suggestedAnswer":[{"@type":"Answer","text":"Trying to get help on the error here<\/p>\n
$MirrorUser = Get-ADUser -filter “givenName -eq ‘Ray’ -and surname -eq ‘Test’”
\n$MirrorThis = Get-ADUser $MirrorUser -Properties *
\nNew-ADUser -Name ‘Raymond Test’ -Instance $MirrorThis<\/p>\n
Error below<\/p>\n
New-ADUser : The operation failed because UPN value provided for addition/modification is not unique forest-wide<\/p>\n
At line:3 char:1<\/p>\n
New-ADUser -Name ‘Raymond Test’ -Instance $MirrorThis<\/p>\n
\n- CategoryInfo : NotSpecified: (CN=Raymond Test…ate,DC=ca,DC=us:String) [New-ADUser], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:8648,Microsoft.ActiveDirectory.Management.Commands.NewADUser<\/li>\n<\/ul>","upvoteCount":7,"datePublished":"2022-03-17T18:06:15.000Z","url":"https://community.spiceworks.com/t/copying-user-powershell/828037/1","author":{"@type":"Person","name":"reubenhyman1629","url":"https://community.spiceworks.com/u/reubenhyman1629"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n