Powershell and Active Directory Part 3/4 Get TS info

64px-Windows_PowerShell_icon Back again with a new post in the Powershell and Active Directory series of posts. Remember when I said I will show you how to work with attributes that are not schema attributes? By default you can do a $var.schemaatrributename like $user.name or $user.DistinguishedName. This is not possible for for example the TerminalServiceHomeDrive attribute because this strange enough is not a schema attribute.

We 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”
$ADSCOPE = “SUBTREE”
$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
$u

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

Variables

$ALLOWLOGON = 1
$TSHOMEDRIVE = “H:”
$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”

Get Information

   $ouuser = $user.psbase.get_parent()

$user2 = $OUUSER.psbase.get_children().find(“CN=$($user.name)”)
foreach ($property in $ALLProperty)

{
“$($Property) value: $($user2.psbase.invokeget($Property))”
}
}

In this part of the script we are going to extract the information from the Active Directory. 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. In the next part of this blog series I will show you how to change these values.

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.

Link

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.
Tagged , , , . Bookmark the permalink.

Leave a Reply