Im looking to add to an existing script for creating a new user to copy the clone user’s homedirectory I have everything working in the script so far but not sure where to start with copying the clone user home Directory.

I can get it to work from CSV files when doing a mass creations but need to define the homedirectory first my clone user is $Clone and new user is $NewUser in my script can set the home drive with Set-ADUser $Newuser -HomeDrive $Clone.HomeDrive

I need to copy $Clone:- \homedrive\UserDrive\User1 and create $Newuser:- \homedrive\UserDrive\User2 either with SamName or %Username%

9 Spice ups

and where are you stuck with that?

Have you looked into ‘copy-item’ and possibly the recurse switch?

e.g.

copy-item "\\server\share\clone" -destination "\\server\share\$samaccountname" -recurse

robocopy might do it it too? really depends on what exactly you need.

Give it a try.

If you post code, please use the ‘Insert Code’ button. Please and thank you!

1 Spice up

Are You try to clone a directory for the ne user or are You just trying to set home directory? If the home directory is the same it can be a part of Your .csv file and referenced in the script.

New-ADUser -DisplayName $item.Name -SamAccountName $item.SamAccountName -HomeDirectory $item.HomeDirectory -HomeDrive $item.HomeDrive

Are you using an -Instance as the account to clone?

If you know the base path of the HomeDirectory, this is easy.
You build a string using the base path plus the new SamAccountName.

Or You can try this, add the HomeDirectoy field to .csv and combine it to samaccountname to add user home directory.

$HomeDIR = $item.HomeDirectory + "\" + $item.SamAccountName
New-ADUser -DisplayName $item.Name -SamAccountName $item.SamAccountName -HomeDirectory $HomeDir -HomeDrive $item.HomeDrive