Setting a users home directory

One task when creating a new user is to set their home directory. This information is on the Profile tab in the lower box.

In the GUI we would use the Connect radio button, select a drive letter and supply the UNC path to a share.  In PowerShell we do this

$ou = "OU=BlogTests,DC=Manticore,DC=org"            
$name = "UserA"            
Get-ADUser -Identity $name |            
Set-ADUser -HomeDirectory "\\fileserver\$name" -HomeDrive "H:"            
"`nAD provider"            
$name = "UserB"            
$dn = "cn=$name,$ou"            
Set-ItemProperty -Path AD:\$dn  -Name homeDirectory -Value "\\fileserver\$name"  -Force            
Set-ItemProperty -Path AD:\$dn  -Name homeDrive     -Value "H:"       -Force            
$name = "UserC"            
Get-QADUser -Identity $name |            
Set-QADUser -HomeDirectory "\\fileserver\$name" -HomeDrive "H:"            
$name = "UserD"            
$dn = "cn=$name,$ou"            
$user = [adsi]"LDAP://$dn"            
$user.homeDirectory = "\\fileserver\$name"            
$user.homeDrive = "H:"            


The cmdlets supply parameters for HomeDirectory and HomeDrive – both fairly obvious

In the provider we have a couple of calls to Set-Itemproperty. The attribute names are self explanatory. The script is similar in that we get a directory entry for the user and set the appropriate attributes.

This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

5 Responses to Setting a users home directory

  1. jkavanagh58 says:

    Nice post. I was called in at the last minute to help with a Windows 7 rollout to script several pieces, one of those pieces is to update the users targeted for upgrade with new login script and HomeDirectory as well as as profile path. There are some conditional pieces involved (i.e. determining sub directory based on a group membership with a split involved…) with determining the new paths. While I did set-qaduser individually, the Quest AD cmdlets make the task much easier.

  2. Del says:

    Is there a way to manipulate this script to run against a csv of user names rather than OU?
    Thanks for the good article and explanation.

  3. Chris Ziemann says:

    Excellent. I can now set the Users Home Directory with Drive Letter. How do I set a user back to a Home Folder / Local Path (with a blank path) i.e In the GUI, I just Click the Local Path radio button and the users Home Directory and Drive letter disappear, I can not figure out how to script that.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s