none
Creating AD Accounts Home Folder Not Working RRS feed

  • Question

  • So have this Powershell script I use to create student profiles in AD. Everything works great except assigning them a home folder network share

    P: with the homedir set to \\xxxx\shares\studenthome\last.firstname

    It sets the name and share\ string correctly but it's not creating the folder for

    the student in the \\xxxx\shares\studenthome\ dir. Now if I delete a character and

    put it back, hit apply, it will create the folder but that's a pain when dealing

    with hundreds of accounts. 


    Any help would be greatly appreciated! 

    Screenshot of the excel file we convert: http://i.imgur.com/sadEQQt.png

    $date = Get-Date 
    #Set up Log files for output 
    $ErrorLog = "C:\Temp\AddStudentssErrorlog.txt" 
    $SuccessLog = "C:\Temp\AddStudentsSuccesslog.txt" 
    Add-Content $SuccessLog "-----------------------------------------------------------------" 
    Add-Content $SuccessLog $date 
    Add-Content $SuccessLog "-----------------------------------------------------------------" 
    Add-Content $ErrorLog "-------------------------------------------------------------------" 
    Add-Content $ErrorLog $date 
    Add-Content $ErrorLog "-------------------------------------------------------------------"
    
    ## Add AD Cmdlets 
    Import-Module ActiveDirectory 
    
    
    $UserList = Import-Csv -Delimiter "," -Path "C:\Temp\teststudentgroup.csv"            
    foreach ($User in $UserList)            
    {            
    
    $Displayname = $User.'Firstname' + ' ' + $User.'Lastname'            
    $UserFirstname = $User.'Firstname'            
    $UserLastname = $User.'Lastname'            
    $OU = $User.'OU'            
    $SAM = $User.'SAM'            
    $UPN = $User.'SAM' + "@" + $User.'Maildomain'            
    $Description = $User.'Description'            
    $Password = $User.'Password' 
    $HomeDirectory = $User.'HomeDirectory'
    $HomeDrive = $User.'HomeDrive' 
    
    
    #Check if the User exists  
    
    
    New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName $SAM -UserPrincipalName $UPN -GivenName "$UserFirstname" -Surname "$UserLastname" -Description "$Description" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Path "$OU" -ChangePasswordAtLogon $false –PasswordNeverExpires $true -Enabled $true -server dc-1.xxxxxxxxxxxx -HomeDirectory $HomeDirectory -HomeDrive $HomeDrive
    
    Add-ADGroupMember -Identity All-Students -Member $SAM     
    
    Write-Host "AD Account $Displayname created!"  
    
    add-content $SuccessLog  "User $Displayname created Sucessfully."
    
    Write-Host -ForegroundColor Green $Displayname




    • Edited by cfiala Thursday, November 3, 2016 5:10 PM
    Thursday, November 3, 2016 4:26 PM

Answers

  • If you don't use Group Policy, then the script must have separate steps to create the folder and assign permissions. This is done automatically for you in ADUC, but not in a script.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, November 3, 2016 5:17 PM
    Moderator

All replies

  • Please fix your post.  It is corrupted.  Read it to see.

    Assigning a folder does not create the folder.

    In modern Windows we use Group Policy to set and create user folders.  Post in GP forum to learn how.  Using the homedrive and homepath is left over from NT4 for compatibility reasons.


    \_(ツ)_/

    Thursday, November 3, 2016 5:04 PM
  • If you don't use Group Policy, then the script must have separate steps to create the folder and assign permissions. This is done automatically for you in ADUC, but not in a script.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, November 3, 2016 5:17 PM
    Moderator
  • Here is what is happening: https://www.coryfiala.com/screenshots/2016-11-03_10-29-36.gif
    Thursday, November 3, 2016 5:31 PM
  • Here is what is happening: https://www.coryfiala.com/screenshots/2016-11-03_10-29-36.gif

    Creating a user in PowerShell does not create a folder.  You must write code to create the folders and set permission. Once set up correctly GP will create the folders the first time the user logs in.

    See you domain or network administrator for assistance and help with understanding how AD and PowerShell work.


    \_(ツ)_/

    Thursday, November 3, 2016 5:36 PM
  • Ok thanks
    Thursday, November 3, 2016 5:42 PM