Managing Terminal Service Settings

by Feb 3, 2015

ActiveDirectory Module

Sometimes you may want to directly access properties related to the terminal service in an Active Directory account. Here is some sample code illustrating how this can be done:

$Identity = 'SomeUserName'

$distinguishedName = (Get-ADUser -Identity $Identity -Properties distinguishedName).distinguishedName
$ADUser = [ADSI]"LDAP://$distinguishedName"

$TSProfilePath = $ADUser.psbase.InvokeGet('terminalservicesprofilepath')
$TSHomeDir = $ADUser.psbase.InvokeGet('TerminalServicesHomeDirectory')
$TSHomeDrive = $ADUser.psbase.InvokeGet('TerminalServicesHomeDrive')
$TSAllowLogOn = $ADUser.psbase.InvokeGet('allowLogon')  
 

Twitter This Tip! ReTweet this Tip!