This project is read-only.
The scripts are great for migrations and overall user home directory management. Questions please send an email to Anthony de Lagarde

The following two scripts are intended for Windows System Administartors to leverage PowerShell
to query Active Directory for the home directory and the current drive mapping of users using the GetHomeDirectory.ps1 script. The output data is dumped into a CSV file in C:\temp.

The second script ModifyHomeDirectory.ps1 will take any CSV file that has the full DN of a user in Active Directory and the new UNC path of the home directory updating the users properties and assigning the home drive to use H:.


A)The Operator must have full administartive rights to update user objects in Active Directory.

B) The scripts can be leveraged from any Windows 7, Windows 8, and Windows Server 2008 R2 system that have the RSAT tools installed.

C) The Active Directory Module for Windows PowerShell is the primary requirement.

D) Any of the following Domain Controllers versions must be in the environment:

Windows Server 2012 (Script Tested)
Windows Server 2008 R2 (Script Tested)
Windows Server 2008 (Script Tested)
Windows Server 2003

E) Powershell execution set to remotesigned on the administrative system.

F) A Windows Server 2003 or 2008 Domain Controller can be leveraged if the Active Directory Management Gateway Service is installed.

The Active Directory Management Gateway binary for Windows Server 2003 and Windows Server 2008 can be downloaded from Microsoft here:

Procedures to Query User Properties:

1. Save both files to C:\temp

2. Open an administrative command prompt and type Powershell. Hit enter.

3. The command prompt will now have a PS at the start of your prompt.

4. Type Get-ExecutionPolicy Hit enter.

5. If the response says "restricted" it needs to be changed to remotesigned.

6. Type Set-ExecutionPolicy RemoteSigned Hit enter.

7. Type Get-ExecutionPolicy Hit enter. The output should now say "remotesigned". If it does not repeat step 6.

8. Now type CD to C:\temp in the command prompt.

9. Type .\GetHomeDirectory.ps1 Hit enter.

10. The script will request the operator to type in the LDAP OU path to query both the home directory and home drive of the users.

11. The script will provide output in a CSV file format giving the full DN of the user, home directory, and the current home drive that their files are mounted on.

12. Open the CSV file in Notepad. Please not you can open the file in Excel, but the fomatting of the data will be affected by the application.

Procedures to Edit User Properties in Active Directory:

1. Copy and rename the CurrentHomeDirectory.csv file that was generated by the GetHomeDirectory.ps1 script to UpdateHomeDirectory.csv and save it in C:\Temp.

2. Open UpdateHomeDirectory.csv in Notepad.

3. First line at the very top of the file please delete it
"#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser".

4. Make sure that the DistinguishedName and HomeDirectory are closed off with double quotes and sepearated by a comma. Example: "DistinguishedName","HomeDirectory".

5. Make sure the DistinguishedName and Homedirectory are closed off with double quotes and sepearated by a comma.

Example : "CN=TestUser1,OU=Users,OU=Test,DC=contoso,DC=adm","\\FileServer-01\OldHome$\TestUser1"

6. Do a global search and replace the file server name and path you want to change the user home directory to use.

Example : "CN=TestUser1,OU=Users,OU=Test,DC=contoso,DC=adm","\\FileServer-02\NewHome$\TestUser1"

7. When finished save the CSV file and make sure that Word Wrap is not enabled.

8. From the open administartive command prompt with PowerShell type .\ModifyHomeDirectory.ps1 Hit enter.

9. The script will run and ask for the location of the CSV file to feed it the updated data. Enter the path C:\temp\UpdateHomeDirectory.csv Hit enter.

10. The script will start to modify the users home directory to the path and set the home drive to H: (You can change the home drive to whatever you like in the script).

11. Once the script finishes updating user properties in Active Directory it will request that you type in the LDAP OU Path of the users that were just modified.

12. Type in the OU LDAP path Hit enter.

13. The script will now take a sixty second delay and then query the users that were just modified in Active Directory.

14. The script will create a new CSV file called HomeDriveVerification.csv and place it in C:\temp for review of the changes.

Last edited Nov 5, 2013 at 12:04 AM by delagardecodeplex, version 4