WindowsAD/SetHomeDirectory.ps1
2025-01-12 11:55:25 -06:00

22 lines
655 B
PowerShell

#path to the Users shared folder
$homepath = "\\hq\CorporateData\Users\"
#initial OU where the script starts searching for the users
$basepath = "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
$users = Get-ADUser -SearchBase $basepath -Filter *
foreach($user in $users){
#Get the current user identity
$identity = $user.SamAccountName
#Get the current user name
$name = $user.Name
#construct the homedirectory path
$homedirectory = $homepath + $name
#Update the current user with the new path to the Home directory.
Set-ADUser -Identity $identity -HomeDirectory $homedirectory
}