![]() |
![]() |
2 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/perl
use warnings;
use strict;
use Win32::OLE;
use Win32::OLE::Variant;
$Win32::OLE::Warn = 3;
my $userDn = "cn=Administrator,cn=Users,dc=my,dc=domain";
my $password = 'password';
my $server = 'server.with.full.domain.name';
# ADSI-Objekt erzeugen und anmelden
my $adConn = Win32::OLE->CreateObject('ADODB.Connection');
$adConn->{Provider} = 'ADsDSOObject';
$adConn->Properties->{'User ID' } = $userDn;
$adConn->Properties->{'Password'} = $password;
$adConn->Open();
# root naming context vom $server ermitteln
my $rootDSE = Win32::OLE->GetObject("LDAP://$server/RootDSE");
my $rootNamingContext = $rootDSE->Get('defaultNamingContext');
# dann eventuell was suchen
my @wantedAttributes = qw( ADsPath cn objectClass member ); # usw
my $searchString = join( ";", "<LDAP://$server/$rootNamingContext>",
"(&(objectClass=groupOfNames)(cn=*))",
join(",", @wantedAttributes ),
'SubTree',
);
my $adoCmd = Win32::OLE->new('ADODB.Command');
$adoCmd->{ActiveConnection} = $adConn;
$adoCmd->Properties->{'Page Size'} = 1000;
$adoCmd->{'CommandText'} = $searchString;
my $searchResult = $adoCmd->Execute($searchString);
unless (ref $searchResult) {
die "Error: couldn't execute searchString: " . Win32::OLE::LastError;
} # unless
while( my $object = &GetNextEntry( $searchResult, \@wantedAttributes ) ) {
# ADSI-Objekt holen
my $object = Win32::OLE->GetObject( $object->{ADsPath} );
# mach was mit dem Objekt
} # while
$searchResult->Close;
# ------------------------------------------------------------
sub GetNextEntry {
my( $searchResult, $attributesRef ) = @_;
return if $searchResult->EOF;
my %object = map {
$attributesRef->[$_] => $searchResult->Fields($_)->value
} 0..$#attributesRef;
$searchResult->MoveNext;
return \%object;
} # GetNextEntry
# ------------------------------------------------------------
![]() |
![]() |
2 Einträge, 1 Seite |