Perl Monks,
In an effort to gain better control over the AD and to diminish the overall ambiguity within ADODB after having added users with the NT modules win32::lanman::NetUserAdd - I am now reorganizing win2000 user attributes in order to gain greater clarity. I have compiled sub programs SearchAD and GetProperties however, I would like to programmatically iterate through users within particular OU’s specifically the nested students OU’s. I need to transcribe the attribute “displayName” to the attribute “userPrincipalName” where displayName =~ s/ /_/; displayName .= “\@domain.net” foreach of the students.
Thanks, PERL MONGERS YOU’RE THE GREATEST :-}
use Win32::OLE;
use Win32::OLE::Const;
my $name = "Microsoft ActiveX Data Objects 2\\.0 Library";
$ado_consts = Win32::OLE::Const->Load($name)
|| die "Unable to load Win32::OLE::Const ``$name'' ".Win32::OLE->LastE
+rror;
$dn = SearchAD( "$username" );#cw0831
print $dn;
#LDAP://CN=$username,OU=$ou,OU=$parent_ou,OU=$parent_ou,OU=
+$parent_ou,DC=domain,DC=net
sub SearchAD
{
($Account) = @_;
undef $AdsPath;
$Root = Win32::OLE->GetObject("LDAP://RootDSE");
$DefaultDomainNC = $Root->Get("DefaultNamingContext");
undef $Root;
if ("" eq $DefaultDomainNC)
{
Win32::MsgBox("Error. Did not get the Default Naming C
+ontext",
MB_ICONSTOP , "Source User Error
+");
return;
}
$ADOConn = Win32::OLE->new("ADODB.Connection");
$ADOConn->{Provider} = ("ADsDSOObject");
$ADOConn->{ConnectionString} = ($DefaultDomainNC);
$ADOConn->Open("Active Directory Provider");
$ADOCommand = Win32::OLE->new("ADODB.Command");
$ADOCommand->{ActiveConnection} = $ADOConn;
$ADSQuery = "SELECT AdsPath FROM \'LDAP://$DefaultDomainNC\' W
+HERE samAccountName = \'$Account\'";
$ADOCommand->{CommandText} = $ADSQuery;
$ResultSet = Win32::OLE->new("ADODB.Recordset");
$ResultSet = $ADOConn->Execute($ADSQuery);
$AdsPath = $ResultSet->Fields(0)->{Value};
$ResultSet->Close;
$ADOConn->Close;
return($AdsPath);
}
$ADSIObj = Win32::OLE ->GetObject( "$dn" );
#$ADSIObj->{$attrib} = "value";
#$ADSIObj->SetInfo; # Don't forget to set the values
my $PropertyList = GetProperties( $ADSIObj );
print "\n\n$ADSIObj->{Name}\n\n";
foreach ( sort( @{$PropertyList} ) )
{
next if( " " eq $_ );
print "\t $_: $ADSIObj->{$_}\n";
}
sub GetProperties
{
my( $Obj ) = @_;
my @Properties;
if ( my $Schema = Win32::OLE->GetObject( $Obj->{Schema} ) )
{
foreach ( $Schema->{MandatoryProperties},
$Schema->{OptionalProperties} )
{
push( @Properties, @{$_} ) if( defined $_ );
}
}
return ( \@Properties );
}
janitored by ybiC: Balanced <readmore> tags around codeblock
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|