Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Changing Home Directory of several users

  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing Home Directory of several users

    I have several users in an OU. I want to change the home directory of these users, but it does not seem lik I can accomplish this With DSQUERY or a single Powershell command.

    dsquery user "ou=regularusers,dc=contoso,dc=com" | dsmod user -hmdir \\server02\users$\$username$

    Sets the exact string \\server02\users$\$username$ as the home Directory

    get-aduser -searchbase "ou=Regularusers,dc=contoso,dc=com" -filter * | set-aduser -homedirectory \\server02\users$\%username%

    Will give me the same results. It does not matter if I use %username% or $username$ the result is the same.

    If I use ADUC, multi Select the users and change the path in the profile tab, I will get the following Message

    The %1 home folder was not created because it already exists. You might want to select a different name, or make sure that the user has full access privileges to the existing one.

    Because the homefolder does already exist (it was moved from one fileserver to another). If I click cancel, the home Directory will be set correctly, and if I try to log on as a user, that user will be Connected to the correct server and home Directory. But still I don't like having to click cancel, to make something work.

    Is this the only solution that works?

  • #2
    Re: Changing Home Directory of several users

    When setting the home directory in ADUC, it automatically tries to create the folder. So the error you're seeing is expected since the folder already exists. But there's no problem, it's just letting you know it's already there and the permissions might not be set correctly.

    For powershell you could try:
    get-aduser -searchbase "ou=Regularusers,dc=contoso,dc=com" -filter * | set-aduser -homedirectory '\\server02\users$\%username%'
    Using the single quote around the path it should put it in as literal text and ADUC should then change it to the appropriate username... but I don't have my test server running so I can't test this out. Not sure if it will work.

    You could also do something like:
    $adusers = get-aduser -searchbase "ou=Regularusers,dc=contoso,dc=com" -filter * 
    foreach($aduser in $adusers){
      $SAM = $aduser.SamAccountName
     set-aduser $aduser -homedirectory \\server02\users$\$SAM

    Network Consultant/Engineer
    Baltimore - Washington area and beyond