3dbc has asked for the wisdom of the Perl Monks concerning the following question:
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