Powershell Script – Automate User Home Path

This is useful in organizations that automate the new account creation process and also have roaming profiles. The following script creates the profile and home path and sets the user’s AD account.

This assumes that when new accounts are created they are put into an OU called NewUsers, and that when this script runs, everyone in NewUsers needs to have a path created. As part of your automation process, don’t forget to move people out of this OU when their setup is complete.

Import-Module Active Directory
$ou = "NewUsers,DC=YOURDOMAIN,DC=com"
$properties = "ProfilePath", "l"
Get-ADuser -Filter * -SearchBase $ou -Properties $properties |

   $ProfilePath = "\\serverName\profiledir\{1}" -f $_.l, $_.SamAccountName
   $HomePath = "\\serverName\homedir\{1}" -f $_.l, $_.SamAccountName

Set-AdUser $_.samaccountname -ProfilePath $ProfilePath -HomeDirectory $HomePath -HomeDrive "I:"

If you want to set a Script Path for your user accounts you can do that here as well with
-ScriptPath “\\path\to\scripts”

Leave a Reply

Your email address will not be published. Required fields are marked *