Solved

Export All AD user Remote Desktop Services Home Directory Path

Posted on 2014-10-03
1
1,356 Views
Last Modified: 2014-10-22
Hi All,

I have been searching over the net for ages and cannot seem to find what i need.

I have in the process of migrating a file server, i have a large number of users who have their home drives configured under the AD Profiles tab and the "Remote Desktop Services" TAB. I have and can easily retrieve all users in my domain attributes for their Profiles Tab home directory path, but cannot do the same for the "Remote Desktop Services Profile " tab. I have seen articles for ldap searches but these do not really do what i want.

All i really need to do is export any user who has a path configured in AD under the "Remote Desktop Services" tab for their home directory.

Ideally using powershell.

I hope to get username, remotedesktop services home directory path (From Remote Desktop Services Profile TAB in AD)

(All DC 2008r2)
Thanks in Advance!
0
Comment
Question by:wanstor
1 Comment
 
LVL 26

Accepted Solution

by:
pony10us earned 500 total points
ID: 40359720
Perhaps give this a try:  

################
<#
.SYNOPSIS
Returns the Home Directory and Remote Desktop Services Home Folder for every user

.DESCRIPTION
This script filled a need to show who's home folder lives where, and if they have a matching (or existing) RDP home folder prior to F/P server migrations. 
Queries AD for all users with a homeDirectory that is not null, checks to see if they have an RDP Home directory, and outputs it all in a nice csv file.

.NOTES
Written by Derek

.Outputs 
Example of output:
Name	    Username	  HomeDrive	            RDP
Bob Marley	BobM050  	\\srv1\homes\BobM050    No
Anne Teak	AnneT024	\\srv2\homes\AnneT024	\\srv2\homes\AnneT024

#>
################

import-module ActiveDirectory
$enabledusers = get-aduser -filter {Enabled -eq "True"} -properties Homedirectory |where {$_.HomeDirectory -ne $null}
$Result = @()
foreach ($user in $enabledusers)
{
$first = $user.givenname
$last = $user.surname
$fullname = "$first $last"
$sam = $user.samaccountname
$Pdrive = $user.homedirectory
$UserDN = $user.distinguishedname
$Person = [ADSI] "LDAP://$UserDN"
$property = "TerminalServicesHomeDirectory"
try{
if($Person.psbase.invokeget($property) -ne $null)
{
$RDPPdrive = $Person.psbase.invokeget($property)
}
if($Person.psbase.invokeget($property) -eq $null)
{
$RDPPdrive = "No"
}
}
Catch
{
[System.Exception]
$RDPPdrive = "No"
}
$o = new-object PSObject
$o | add-member NoteProperty Name $fullname
$o | add-member NoteProperty Username $sam
$o | add-member NoteProperty HomeDrive $Pdrive
$o | add-member NoteProperty RDP $RDPPdrive
$Result += $o
}
$Result | export-csv "C:\Users\derek\Desktop\BothPDriveOut.csv" -notype -append

Open in new window


I got this from Spiceworks forum (http://community.spiceworks.com/scripts/show/1946-get-home-and-rdp-home-directories) and it has worked for us.
0

Featured Post

Do email signature updates give you a headache?

Do you feel like all of your time is spent managing email signatures? Too busy to visit every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Join & Write a Comment

I have been working as System Administrators since 2003. I recently started working as a FreeLancer and was amazed to find out that very few people are taking full advantage of their Windows Server Machines. Microsoft Windows Server comes with so…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now