Configure Home Directory for AD Users with PowerShell

Steps to configure Home Directory for AD Users with PowerShell

Preparation of Share Folder with Share & NTFS Permission

  1. Create a Folder called HOME in File Server with Allow Full Access Share Permission for Lab\Domain Users
New-Item -Path "C:\HOME" -ItemType Directory 
New-SmbShare -Name "HOME" -Path "C:\HOME" -FullAccess "Lab\Domain Users"

  1. Block the Inheritance permission from parent folder, and remove all the existing users’ permission
$acl = Get-Acl \\\HOME
#First Parameter - To block Inheritance from the parent folder
#Second Parameter - $False = To Remove all existing Folder Permission , $True = To Retain
$acl | Set-Acl \\\HOME
  1. Manually assign permission to Administrators, Creator Owner, SYSTEM, and Users
#Permission for CREATOR OWNER
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("CREATOR OWNER","FullControl", "ContainerInherit, ObjectInherit", "InheritOnly", "Allow")

#Permission for Administrators
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "InheritOnly", "Allow")

#Permission for SYSTEM
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")

#Permission for Users
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","CreateFiles, AppendData, ReadAndExecute, Synchronize", "None", "None", "Allow")

#Apply NTFS permission to folder
$acl | Set-Acl \\\HOME
  1. Select Administrators and change Applies to This Folder, subFolders and Files

Final Configuration of NTFS Security Permission for C:\HOME or \\HOME

Configuration of Home Folder for individual user

  1. Configure HOME Folder for User
$User = "UAT2"
$ShareDrive = "\\\HOME\"

#Home folder H: is pointing to \\\HOME
Set-ADUser -Identity $User -HomeDirectory ($ShareDrive + $User) -HomeDrive "H:" 

We have to manually assign the NTFS permission for the users’ home folder, else users are NOT able to map to their home drive when they login

#Manually provision the users' home folder 
New-Item -ItemType directory -Path $ShareDrive -Name $User

#Get the exiting ACL 
$acl = Get-Acl ($ShareDrive + $User)

#Assign Domain\$user to have full access to thier individual folder
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("lab\$user","FullControl","Allow")

#Apply the folder permission 
$acl | set-acl ($ShareDrive + $User)
  1. H drive will be mapped to \\Username , and users (UAT1) will be blocked from accessing other users’ folder via Share UNC path

Leave a Comment