Home Drive not mapping

We have a script that runs that creates new users, this script also creates their mailbox and does it from a csv file that is created by filling in a form.

It seems like when we create a user and give them a home drive/directory this shows within AD but does not map on logon, and when you run the set command it truncates it from \\server\userhome\%username% to \\server\userhome (the user only has permission at \\server\userhome\%username%, this works if we manually create the account but does not work if you script it.

the script that creates the user and does the ad bits (not exchange).  (see attached)

our estate is both xp and windows 7 (mid upgrade) and it does not map on either, there is no deletion of old drives at current.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Try this:
$username in your code can be blank so is the reason.
$username = "$([Environment]::UserName)"

new-aduser -path "OU=New Accounts,OU=NewUsers (Unused Accounts),OU=Users,OU=organisation,DC=company,DC=co,DC=uk" -samaccountname $username -Name "$firstname $lastname" -givenname $firstname -surname $lastname -enabled $true -userprincipalname $upn -displayname "$firstname $lastname" -scriptpath "logon" -accountpassword (convertto-securestring $password -asplaintext -force) -ChangePasswordAtLogon $True -profilepath "\\stanmore\users\$username\newxp" -HomeDrive "H" -HomeDirectory "\\stanmore\userhome\$username" -otherattributes @{'extensionAttribute10' =$a10} -manager $manager -company $a10 -Department "$directorate - $department" -Description "Employment Type $employmenttype, Requested By $requestedby, Request ID $requestid" -Officephone $phone -MobilePhone $mobile -office $office -AccountExpirationDate $expirationdate -Title $title

Open in new window

Justin YeungSenior Systems EngineerCommented:
I can't give you an answer until see the full script, I am pretty sure you have more beside just the line.

Raheman, it is not only $username is not specificed, all other are not as well $firstname $lastname $upn and so.

and also if you use $env:Username for this command, it will just create the path with the user who ever ran this.

how can the user create a new ad user without having an account?
NytramAuthor Commented:
Justin, here is the whole script, it reads from a CSV which has all the fields filled in, the script creates the user just fine, and fills the home directory field in, when the user logs in, the user does not get a mapped drive but works for folder redirection

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Justin YeungSenior Systems EngineerCommented:
You meant it has a home directory field in Ad profile but not mapping the home drive H:?

Or it doesn't map other drive that should be from the logon script?
NytramAuthor Commented:
The home directory field is populated as is the drive to connect within AD, it does not map when we log into the accounts that are created, the drives that are mapped by the logon script are all mapped correctly, nothing in the logon script references a H drive.
Justin YeungSenior Systems EngineerCommented:
Question 1.
It seems like when we create a user and give them a home drive/directory this shows within AD but does not map on logon

Do you have more than 1 domain controller in your company? does it take time for the replication?
you script doesn't specific which domain controller to create the user

Question 2
and when you run the set command it truncates it from \\server\userhome\%username% to \\server\userhome (the user only has permission at \\server\userhome\%username%, this works if we manually create the account but does not work if you script it.

what do you mean by running the set command? is that you tried to run the command manually with %username% on your powershelll command?
NytramAuthor Commented:
We have 3 DC's, the replication is very quick here, and the creation script is done overnight and the created users often don't log in for a couple/3 days.

if you log into an account (we created a test account) to test this and go to cmd and type in set, the information brought up from the command the home homeshare is truncated to \\server\userhome and the homepath is \documents and settings\username whereas when we run it on a user that was created manually it the homepath is \ and the homeshare is \\server\userhome\username
Justin YeungSenior Systems EngineerCommented:
so from my understanding, when you place the path on to the profile path, It will not create the folder structure for you.
another word the folder doesn't exist...... however homedirectory does......

let me know if that's the case.
NytramAuthor Commented:
The folder creates perfectly, we can browse to it, we use folder redirection for our my documents folder, this writes to the correct location, the drive however does not map
Justin YeungSenior Systems EngineerCommented:
when you run the script to create the user, does the folder created automatically?

I don't see that in your script with that function.

it doesn't matter on folder redirection, it should still show up as my documents and just the path is redirected.

the profile path is the actual path of the user
when you do echo %profilepath% that is what it should come up but not c:\users\xxx\

did you try to create a brand new user and see if any folder created automatically under the profile path?
NytramAuthor Commented:
AD automatically creates the folder for us, the folder exists and you can browse to this, the issue we are having is that it is that the when the user logs in, their home drive does not map as a drive as it normally would if you created the user automatically, all folders are created as they would normally be
NytramAuthor Commented:
This is now resolved,

There were two seperate issues, these were a missing : after the H in the -homedrive part of new-aduser, and permissions were not inheriting properly from our file server and so this has no been resolved with set-acl

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NytramAuthor Commented:
I found a missing : when comparing a script created user and my normal user, then i found a permission issue which is also now resolved
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.