20080404 search on active directory with win32ole - plembo/onemoretech GitHub Wiki

title: Search on Active Directory with Win32::OLE link: https://onemoretech.wordpress.com/2008/04/04/search-on-active-directory-with-win32ole/ author: lembobro description: post_id: 545 created: 2008/04/04 13:02:12 created_gmt: 2008/04/04 13:02:12 comment_status: open post_name: search-on-active-directory-with-win32ole status: publish post_type: post

Search on Active Directory with Win32::OLE

As I find myself being pulled ever so slightly into the vortex that is Microsoft Active Directory administration (part of a global messaging initiative, i.e. global MS Exchange), I’ve begun to collect stuff like this.

Its a script that takes a list of IDs and does a search on each ID against Active Directory, mostly stolen from my neighbor down here in Cary, NC, Cisco’s own Robbie Allen. The big difference between this and a lot of the other stuff I do is that I’m using the Win32::OLE module rather than Net::LDAP to do the work. Win32::OLE is only available for Perl on Windows machines, but it does allow you to access most if not all of the proprietary features that Microsoft had hidden from pure LDAP operations, and so it’s valuable to begin learning how to make it sing.

`

#!perl
use Text::ParseWords;
use Win32::OLE;
	
my($adHost);
	
my $strBase    =  ";”;
my $strAttrs   = “givenname,sn,displayname,mail;”;
my $strScope   = “Subtree;”;
	
$Win32::OLE::Warn = 3;
my $objConn = Win32::OLE->CreateObject(”ADODB.Connection”);
$objConn->{Provider} = “ADsDSOObject”;
$objConn->Open;
	
my $infile = “../testlist.txt”;
	
open FH, “<$infile" or die $!;
	
while() {
	
   chomp;
	
   my( $userid	) = ( &parse_line(’,',0,$_));
	
   my $strFilter  = “(cn=$userid);”;
	
   my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs 
   . $strScope);
	
   $objRS->MoveFirst;
	
   while (not $objRS->EOF) {
	
      print $objRS->Fields(0)->Value,”n”;
	
     $objRS->MoveNext;
	
   }
	
}
	
close FH;
	
__END__;

`

Copyright 2004-2019 Phil Lembo