Get AD RDS Profile information

I needed to get information which is located in the AD user information, which is located on the tab “Remote Dekstop Services Profile”, which gives the user Profile Path, Home Folder drive and location of the Home Folder on the network (see image below).

AD user RDS Profile tab

I also wanted to check if the given path in this screen can be reached, thus the Test-Path command can be used for that cause.

It appeared that the Get-ADUser couldn’t give me this information, and after some searching, it appeared that this had to be done via ADSI.

Since not all users in our network have a home folder entered, the Test-Path command can give errors and I wanted to log which user accounts gave these kind of errors, thus I added a Start-Transcript to log all output of the script. I also wanted to export this information to a csv, thus I added an Export-CSV in the end (with a “;” as delimiter, since this is the default delimiter for Excel in my country).

When getting the data via ADSI, I need to get the information for

  • TerminalServicesProfilePath
  • TerminalServicesHomeDirectory
  • TerminalServicesHomeDrive

You need to change the searchbase part in this command to get the users from the OU in your domain (it will only get the information for enabled accounts in the given OU):

Get-ADUser -Filter {Enabled -eq $true} -SearchBase 'OU=UsersOU,DC=domain,DC=com'

The entire script will become:

Start-Transcript $PSScriptRoot\GetRemoteDesktopServicesProfileInformation.txt
$Results = @()
Get-ADUser -Filter {Enabled -eq $true} -SearchBase 'OU=UsersOU,DC=domain,DC=com' | ForEach {
$UserInfo = [ADSI]"LDAP://$($_.distinguishedName)"
Write-Host ("Prosessing {0}" -f $_.distinguishedName)
$Prop = @{
SamAccountname = $_.Samaccountname
TSProfilePath = $UserInfo.TerminalServicesProfilePath
TSHomeDirectory = $UserInfo.TerminalServicesHomeDirectory
TSHomeDrive = $UserInfo.TerminalServicesHomeDrive
PathTestOk = Test-Path -Path $UserInfo.TerminalServicesHomeDirectory
}
$Result = New-Object -TypeName PSObject -Property $Prop
$Results += $Result
}
$Results | Export-Csv $PSScriptRoot\RDSI.csv -Delimiter ";" -NoTypeInformation
Stop-Transcript

You can download the entire script here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s