-----Original Message-----
From: Norris, Joseph [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 27, 2002 12:53 PM
To: Perl Win32 Users (E-mail)
Subject: Active Directory question
I have the script below and so far it is working accept for one thing.
What I really need to get at is the Phone number. Can you tell me if I am
going about this the wrong way? I hacked some stuff from the Win32 Perl
Scripting book (BTW - excellent book). So if there is anything I need to
clean up please let me know. In addition I can not find any source of
how to update the Active directory with Perl.
Thanks.
script:
use Win32;
use Win32::OLE qw( in );
use Win32::OLE::Const 'Active DS Type Library';
my %Config;
my $user_name = $ARGV[0];
$Config{path} = "WinNT://" . Win32::DomainName();
if( $AD = GetADSIObject( \%Config ) )
{
my $iCount = 0;
my $Schema = Win32::OLE->GetObject( $AD->{Schema} );
if( $Schema->{Container} ) {
$AD->{Filter} = "f=user";
my $Object;
foreach $Object ( in( $AD ) ) {
next if ($Object->{Class} ne 'User');
++$iCount if ($Object->{Name} eq $user_name);
if ($iCount){
my $User = $AD->GetObject("", $Object->{Name});
print "name: $User->{Name}\n";
print "Phone: $User->{TelephoneNumber}\n";
my $PropertyList = GetProperties( $User );
foreach my $Property ( sort( @{$PropertyList} ) ){
next if( "" eq $Property );
print "\t $Property: $Object->{$Property}\n";
}
last;
}
}
if (!$iCount){
print "user - $user_name not found\n";
} else {
print "found - $user_name\n";
}
} else {
print "The '$AD->{ADsPath}' is a $AD->{Class} object.\n";
}
}
sub GetADSIObject {
my( $Config ) = @_;
my $ADSIObject;
my $ADsPath = $Config->{path};
$ADSIObject = Win32::OLE->GetObject( $ADsPath );
return( $ADSIObject );
}
sub GetProperties
{
my( $Obj ) = @_;
my @Properties;
if( my $Schema = Win32::OLE->GetObject( $Obj->{Schema} ) )
{
foreach my $PropList ( $Schema->{MandatoryProperties},
$Schema->{OptionalProperties} )
{
push( @Properties, @{$PropList} ) if( defined $PropList );
}
}
return( \@Properties );
}
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs