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”
$ADSCOPE = “SUBTREE”
$strFilter = “(&(objectCategory=User))”
$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
$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
$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.