troubleshooting Question

Powershell and New-QADUser

Avatar of Neptune IT
Neptune ITFlag for United States of America asked on
Windows Server 2008PowershellActive Directory
7 Comments1 Solution1027 ViewsLast Modified:
Greetings All,

I am trying to create a script that will copy an existing user and will use the variables provided to create a new user using that copy. Code below:

Set-ExecutionPolicy RemoteSigned
$fname = Read-Host 'What is their first name?'
$lname = Read-Host 'What is their last name?'
$uname = Read-Host 'What is their user name?'
$pass = Read-Host 'What is the users password?' -AsSecureString

$permission = Read-Host 'Would you like to create the user? Y or N.'

If($permission-eq 'Y') 
Get-QADUser [redacted] -export 

New-QADUser -ParentContainer '[redacted]' -SamAccountName $uname -DisplayName write-host "$lname $fname" -FirstName $fname -LastName $lname -UserPassword $pass -import

Set-QADUser write-host "$lname $fname" -UserMustChangePassword $true

Get-QADMemberOf '[redacted]' | Add-QADGroupMember -Member [redacted]\$uname.

Open in new window

The issue that I am running in to is that it is telling me that the user already exists when I allow it to proceed and then fails to set the new user to must change password and to get the group membership of the template.

Of course the redacted sections are for privacy.
Subash Sundharan
IT Infrastructure Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros