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"            
            
"`nMicrosoft"            
$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            
             
"`nQuest"            
$name = "UserC"            
Get-QADUser -Identity $name |            
Set-QADUser -HomeDirectory "\\fileserver\$name" -HomeDrive "H:"            
            
"`nScript"            
$name = "UserD"            
$dn = "cn=$name,$ou"            
$user = [adsi]"LDAP://$dn"            
$user.homeDirectory = "\\fileserver\$name"            
$user.homeDrive = "H:"            
$user.SetInfo()

 

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.

Published Wed, Feb 29 2012 20:53 by RichardSiddaway

Comments

# Home folders using local path

On the profile tab there are two options for setting the home folder.  We have already seen the

Friday, March 02, 2012 1:44 PM by Richard Siddaway's Blog

# re: Setting a users home directory

Hey thanks so much for sharing.  How would you search and only update users who don't have a homedirectory and homedrive specified?  

Monday, July 30, 2012 9:02 AM by Paul Morrison

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: