Listing19_List_Connections_IadsTools (Perl)

This code can be found in Chapter 9 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4

use strict;
use Win32::OLE;

# Query information
my $dc   = 'dc2';
my $site = 'RTP';

# Authentication information
my $user   = 'administrator';
my $passwd = 'password';
my $domain = 'XYZ';

my $i = Win32::OLE->new("IADsTools.DCFunctions");
my $res = $i->SetUserCredentials($user,$domain,"",$passwd);
die "Authentication failed in SetUserCredentials\n" if $res != 0;

my $num_conns = $i->GetDSAConnections($server,$site,$dc,1);
if ($num_conns == -1) {
   print "There was an error retrieving the connection objects\n";
}
elsif ($num_conns == 0) {
   print "$dc has no connection objects\n";
}
else {
   print "$dc has $num_conns connection objects:\n";
   for my $c(1..$num_conns) {
      print "Name: ",$i->DSAConnectionName($c),"\n";
      print "\tServer: ",$i->DSAConnectionServerName($c),"\n";
      for my $c2(1..$i->DSAConnectionReasonCount($c)) {
         print "\tNC $c2: ",$i->DSAConnectionReasonPartition($c,$c2),"\n";
         print "\tReason $c2: ",$i->DSAConnectionReasonCode($c,$c2),"\n";
      }
      print "\tGenerated: ",$i->DSAConnectionAdminGenerated($c),"\n";
      print "\tNotify: ",$i->DSAConnectionNotify($c),"\n";
      print "\tNotify Override: ",$i->DSAConnectionNotifyOverride($c),"\n";
      print "\tTwo-way: ",$i->DSAConnectionTwoWay($c),"\n";
   }
}

This code has been viewed 582 times.

New from the creators of TechTasks.com: StatSheet.com