Powershell and Active Directory Part 4/4 Set TS info

image Here we are with already the latest part in the Powershell and Active Directory blog series. In part 3/4 we worked with getting information from AD Object attributes which are not defined in the schema. In this part we will work on modifying the settings on these attributes.


Just like in Part 3/4 we will start with were we left of in the Powershell and Active Directory Part 2/4 post. I will repeat the script blocks but for help on these read that post!

After that we continue with the get TerminalServicesProfile atrributes which are not in the schema.

Powershell and Active Directory Part 2/4

Variables Part 2

$TARGETOU = “OU=Users,dc=Bladiebla,dc=COM”
$strFilter = “(&(objectCategory=User))”

AD Searcher

$objOU = New-Object System.DirectoryServices.DirectoryEntry(”LDAP://$TARGETOU“)
$ADSearcher = New-Object System.DirectoryServices.DirectorySearcher
$ADSearcher.SearchRoot = $objOU
$ADSearcher.PageSize = $ADSIZE
$ADSearcher.Filter = $strFilter
$ADSearcher.SearchScope = $ADSCOPE

AD Search Result

$ADResults = $ADSearcher.FindAll()

foreach ($ADResult in $ADResults)
$u = $ADResult.Properties

AD User Object

    $user = [ADSI]“LDAP://$($u.distinguishedname)”

Make sure you notice that we did not close the loop with the }.


Powershell and Active Directory Part 3/4


$ALLProperty = “allowLogon”,”TerminalServicesHomeDirectory”

So now we can create the variables we are going to use in the next part of the Script

The variables we can use for the Terminal Services Profile Tab are

  • “allowLogon”
  • “TerminalServicesHomeDirectory”
  • “TerminalServicesHomeDrive”
  • “TerminalServicesProfilePath”

Set Information

$user2 = $OUUSER.psbase.get_children().find(“CN=$($user.name)”)



In this part of the script we are going to modify settings on the AD object attribute. What you can do here is for example create a variable with the value of the TerminalServicesHomeDrive. I used this for migrating the TS Home Drive to another location.

If you have any questions don’t hesitate to contact me by e-mail or comments.

For now greetings and please come back later for the next part.


Tagged , , , . Bookmark the permalink.

About Barry Schiffer

Barry is an IT Architect with 15 years of IT experience. He has gained both a broad and deep knowledge in the sphere of IT. Throughout the years, Barry has developed into a specialist in the field of Microsoft Windows, Server Based Computing, desktop and server virtualisation.Barry is co-founder and member of the Board of the Dutch Citrix User Group.Barry is awarded with the Citrix Technology Professional award in 2015 and received the RES Software Valued Professional award in 2012.

3 Responses to Powershell and Active Directory Part 4/4 Set TS info

  1. Hi, cool post. I have been wondering about this topic,so thanks for writing.

  2. Dale Menken says:

    This is good stuff but Powershell v2.0 breaks your code. Have you been able to modify it for v2.0? I have found several variations of your code via Google but non work on v2.0.

Leave a Reply