Use the blue Nav bar above to access the main index pages!

Enable OCS Users in Active Directory using Perl

Here's a Perl script that reads user names from a text file and enables them for OCS (Office Communications Server). Click here to view this solution in VBScript.

A couple of notes: I point to an existing user as a template to copy they're OCS meeting Policies (cheating I know), I've hard-coded the distinguished name of the template user and I've also hard-coded the distinguished name of the OCS Pool. You'll have to put the correct DN's for your environment. Also, the options flags I've set are for pc-pc communications with enhanced presence enabled. And lastly, the script assumes that you're not using Enterprise Voice, so the bridge URI and telephone number are not populated.

Let me know if you need help with that. The code is below. Please visit our OCS Scripts Repository.

use Win32::OLE;
# this file contains a list of usernames that we want to enable for OCS
open IN,"enable.txt";
# use another user with the correct OCS meeting policies as a template
$templateUser=Win32::OLE->GetObject("LDAP://CN=myTemplateUser,cn=Users,DC=myDomain,DC=com");
$policySet=$templateUser->Get("msRTCSIP-UserPolicy");
# this is the distinguished name of my OCS Pool
$homeServerDN = "CN=LC Services,CN=Microsoft,CN=POOL1,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=myDomain,DC=com";
#search setup
$dse=Win32::OLE->GetObject("LDAP://RootDSE");
$root=$dse->Get("RootDomainNamingContext");
$adpath="GC://$root";
$base="<".$adpath.">";
$c = Win32::OLE->new("ADODB.Connection");
$c->{Provider} = "ADsDSOObject";
$c->Open("ADSI Provider");
$comm=Win32::OLE->new("ADODB.Command");
$comm->{ActiveConnection}=$c;
$comm->{Properties}->{'Page Size'}=1000;
$rs = Win32::OLE->new("ADODB.RecordSet");
while(<IN>){
 chomp($user=$_);
 $comm->{CommandText}="$base;((cn=$user)(samaccountname=$user));distinguishedName;subtree";
 $rs=$comm->Execute;
 until ($rs->EOF){
  $dn=$rs->Fields(0)->{Value};
  if($userobj=Win32::OLE->GetObject("LDAP://$dn")){
   $userMail = $userobj->{mail};
   # get the user's email address from AD
   $userobj->Put("msRTCSIP-ArchivingEnabled", 0); # 0 for off - 4 for on
   $userobj->Put("msRTCSIP-FederationEnabled", TRUE); # allow federation
   $userobj->Put("msRTCSIP-OptionFlags", 256);    # pc-pc only, enhanced presence enabled
   $userobj->Put("msRTCSIP-PrimaryHomeServer", $homeServerDN);    # point to the Pool set above
   $userobj->Put("msRTCSIP-PrimaryUserAddress", "sip:$userMail"); # set the sip address to the email address
   $userobj->Put("msRTCSIP-UserEnabled", TRUE);                   # enable the user
   $userobj->Put("msRTCSIP-UserPolicy", $policySet);              # set the OCS meeting policy like the template user
   $userobj->SetInfo();                                           # write the changes
   print "$user ".Win32::OLE->LastError()."\n";                   # report error level - 0 is success
  }else{
   print "$user failed to access\n";
  }
 $rs->MoveNext;
 }
}

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...