Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I tried to create user using New-QADUser cmdlet. I know this cmdlet has -HomeDrive switch. But the problem is that cmdlet is just applying path string to user's account and not creating user's home directory on the fileserver like it happens when you use ADUC console. How can I do it corerctly?

share|improve this question
add comment

3 Answers 3

Does the script that is creating the user account have administrative access to the file server as well?

Why not let the script create the home drive? very simple example:

$user = read-host -prompt "Enter Username"
$server = "HOMEDRIVESERVER"
$share = "usershare$"
New-QADUser -name $user etc..
newitem -path \\$HOMEDRIVERSERVER.domain.com\$share -name $user -itemtype directory

The only gotcha here is then setting the ACLs on the folder, that could possibly be done with set-acl. A bit more info on ACLS here..

http://chrisfederico.wordpress.com/2008/02/01/setting-acl-on-a-file-or-directory-in-powershell/

The nice thing about scripting it in this way is being able to then output what it is doing to a log file for script auditing purposes. Of course, it doesn't necessarily give you the 1-step nicety the MMC console does.

share|improve this answer
1  
Thanks a lot! Your advice was totally helpful. –  Maximus Mar 12 '10 at 7:13
add comment
up vote 2 down vote accepted

Resulting code for creating and connecting home drive to user with $Sam sam account name:

$HomeDir = "<Path>"
$Sam = "<User's Sam Account Name>"
$User = Get-QADUser -SamAccountName "$Sam"
New-Item -Path $HomeDir -Name $Sam -ItemType Directory
$UserDir = "$HomeDir\$Sam"
$Rights = [System.Security.AccessControl.FileSystemRights]::FullControl
$Inherit=[System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$Propogation=[System.Security.AccessControl.PropagationFlags]::None
$Access=[System.Security.AccessControl.AccessControlType]::Allow
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("$Sam",$Rights,$Inherit,$Propogation,$Access)
$ACL = Get-Acl $UserDir
$ACL.AddAccessRule($AccessRule)
Set-Acl $UserDir $ACL 
Set-QADUser -Identity $User -HomeDirectory "$UserDir" -HomeDrive "Z:"
share|improve this answer
add comment

powershell setfolderpermission.ps1
download from http://www.powershell.nu/wp-content/uploads/2009/02/setfolderpermission.ps1

Function CreateHomeFolder {
  Param($userinfo)
  $homeserver = '\\homeserver'
  $HomeFolderRoot = "\home\'
  Mkdir ($homeserver + $HomeFolderRoot + $userinfo['AccountName'])
}

Function UpdateHomeDirRights2 {
  Param($userinfo)
  $homeserver = '\\taz'
  $HomeDrive = "S"
  $HomeFolderRoot = "\home\'
  $HomeDirectory = $homeserver + $HomeFolderRoot + $userinfo[*'AccountName'*]
  ./SetFolderPermission.ps1 -path $HomeDirectory -Access  $userinfo[*'UserPrincipalName'*] -Permission FullControl
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.