I have a very simple PowerShell script that renames user logons (sAMAccountName, UserPrincipalName). I'd like to also include a way to rename their associated home directories.
Folder Redirection is being applied to the home directories. (User Configuration > Policies > Windows Settings > Folder Redirection > Documents > Settings: Basic (Redirect everyone's folder to the same location))
Path: \\lab-dc-01\StudentHomeDirectories\%USERNAME%\Documents
Options:
- Grant user exclusive rights to Documents (Enabled)
- Move the contents of Documents to the new location (Enabled)
- Also apply redirection policy to Windows 2000, Windows 2000 server, Windows XP, and Windows Server 2003 operation systems (Disabled)
- Policy Removal Behavior (Restore contents)
NOTE: I just followed TechNet's recommended way of setting up Folder Redirection, but I'm thinking of changing this.
My PowerShell Script to rename user logons is as follows:
Import-Module ActiveDirectory
$StudentList = Import-CSV C:\PowerShell\Rename_User_Logon\2012StudentList.txt
ForEach ($Student in $StudentList){
Get-ADUser -Filter "sAMAccountName -eq '$($Student.StudentID)'" -Search 'OU=2012,OU=SPS Students,DC=TEST,DC=LAB' |Set-ADUser -sAMAccountName "$($Student.sAMAccountName)" -UserPrincipalName "$($Student.UserPrincipalName)"}I'd like to add the cmdlet Rename-Item to rename the users' home directories. I'm not sure how to add it though. If I manually do this, it works, but I have problems on the client side. For example, the folder path is \\lab-dc-01\StudentHomeDirectories\StudentID. If I rename the "StudentID" folder to "StudentName", and then the user logs on to a Windows 7 Prof computer, their "Documents" isn't available because the folder "StudentID" is no longer working. If the user manually browses to the new folder path, it works. Not sure how to fix this though...
Any thoughts on this issue?
Thank you