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->LastError; $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 Context", 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\' WHERE 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 ); }