Quantcast
Channel: www.barryschiffer.com
Viewing all articles
Browse latest Browse all 6

Powershell and Active Directory Part 4/4 Set TS info

$
0
0

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”
$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”

Set Information

$user2 = $OUUSER.psbase.get_children().find(“CN=$($user.name)”)
$user2.psbase.invokeSet(“allowLogon”,$ALLOWLOGON)
$user2.psbase.invokeSet(“TerminalServicesHomeDirectory”,$TSHD)
$user2.psbase.invokeSet(“TerminalServicesProfilePath”,$TSPP)
$user2.psbase.invokeSet(“TerminalServicesHomeDrive”,$TSHOMEDRIVE)
$user2.setinfo()

}

 

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.

Link

The post Powershell and Active Directory Part 4/4 Set TS info appeared first on www.barryschiffer.com.


Viewing all articles
Browse latest Browse all 6

Trending Articles