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

Reading a User's OCS Properties with a Perl Script

OCS script to retrieve a user's Office Communication Server properties: A visitor just requested this script.  Great idea.  Here's a Perl script that retrieves all of a user's OCS properties. You can also find the PowerShell version of this code in the article - Read OCS User Properties with PowerShell.

The script uses ADODB to search the Active Directory for the user, retrieves each of the OCS related attributes, and prints them to the screen.  It's a handy way to determine if the user is OCS enabled, what their SIP address is, what policies are set, whether the user's IM's are archived, etc.

The script demonstrates how to read each of these properties, including the option flags, which is a bit mask of various options, as well as the policies, which are DNwithBinary objects that require a little skill to unpack.

To use the script, you have to have Perl of course, which can be downloaded free from ActiveState. Next, copy the code and save it as a perl script file, such as then, from the command prompt, launch the script, using the user name (common name, logon name, or display name) as the argument.  Use quotes around the user name if there are any spaces in it.  Examples are: myUser "Seltzer, Brian"

Here's the script:
use Win32::OLE;
use XML::Simple;
# setup ADODB search parameters
$c = Win32::OLE->new("ADODB.Connection");
$c->{Provider} = "ADsDSOObject";
$c->Open("ADSI Provider");
$comm->{Properties}->{'Page Size'}=1000;
$rs = Win32::OLE->new("ADODB.RecordSet");
if($rs->{recordCount} < 1){
 print "$user not found\n";
until ($rs->EOF){
  print "\nOCS Properties for $userobj->{cn} ($userobj->{displayName}):\n\n";
  #is the user enabled?
  if($enabled == 1){ $enabled = "True"; }else{ $enabled = "False"; }
  print "\t     Enabled for OCS:\t$enabled\n";
  if($enabled eq "True"){
   print "\t    User SIP Address:\t".$userobj->Get("msRTCSIP-PrimaryUserAddress")."\n";
   print "\tUser OCS Pool/Server:\t".(split /,CN=/,$userobj->Get("msRTCSIP-PrimaryHomeServer"))[2]."\n";
   if(ref($pol) eq "ARRAY"){
    foreach $p (@{$pol}){
   if($archive == 0){ $archive="False"; }else{ $archive = "True"; }
   print "\t   Archiving Enabled:\t$archive\n";
   if($federation == 0){ $federation = "False"; }else{ $federation = "True"; }
   print "\t  Federation Enabled:\t$federation\n";
   #option Flags
   if(($flags & 1) == 1){ $pim = "True"; }else{ $pim = "False"; }
   if(($flags & 16) == 16){ $rcc = "True"; }else{ $rcc = "False"; }
   if(($flags & 64) == 64){ $oam = "True"; }else{ $oam = "False"; }
   if(($flags & 128) == 128){ $uce = "True"; }else{ $uce = "False"; }
   if(($flags & 256) == 256){ $ep = "True"; }else{ $ep = "False"; }
   if(($flags & 512) == 512){ $rcd = "True"; }else{ $rcd = "False"; }
   if(($flags & 1024) == 1024){ $aa = "True"; }else{ $aa = "False"; }
   print "\n\t        Option Flags:\t$flags\n";
   print "\t    Public IM Enabed:\t$pim\n";
   print "\t Remote Call Control:\t$rcc\n";
   print "\t  Anonymous Meetings:\t$oam\n";
   print "\t       Unified Comms:\t$uce\n";
   print "\t   Enhanced Presence:\t$ep\n";
   print "\t  Rmt Call Dual CTRL:\t$rcd\n";
   print "\t      Auto Attendant:\t$aa\n";
  print "$user access denied\n";
sub readPolicy{
  foreach $byte (@byteArray){
  if($binString eq "01000000"){  $poltype=" Meeting Policy"; }
  if($binString eq "02000000"){  $poltype="   Voice Policy"; }
  if($binString eq "04000000"){  $poltype="Presence Policy"; }
  $polname = $hashref->{property}->{Name}->{content};
  print "\t     $poltype:\t$polname\n";

Enjoy!  We appreciate the visitor's request.  It's good to know what people are looking for, and we're happy to help when we can.


Post a Comment

Related Posts Plugin for WordPress, Blogger...