Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simondegheselle/b4673ad5c82330e8b35d9a823a002ac6 to your computer and use it in GitHub Desktop.
Save simondegheselle/b4673ad5c82330e8b35d9a823a002ac6 to your computer and use it in GitHub Desktop.
use Win32::OLE qw(in);
use Win32::OLE::Const "Active DS Type Library";
$root_dse = bind_object("RootDSE");
$root_dse->GetInfo();
$con = Win32::OLE->new("ADODB.Connection");
$con->{Provider} = "ADsDSOObject";
$con->{Properties}->{"User ID"} = "Interim F";
$con->{Properties}->{"Password"} = "Interim F";
$con->{Properties}->{"Encrypt Password"} = True;
$con->Open();
$cmd = Win32::OLE->new("ADODB.Command");
$cmd->{ActiveConnection} = $con;
$domein = bind_object($root_dse->Get(defaultNamingContext));
$base = $domein->{AdsPath};
$filter = "(&(objectClass=user)(objectCategory=person))";
$attr = "sAMAccountName";
$scope = "subtree";
$cmd->{CommandText} = "<$base>;$filter;$attr;$scope";
$res_set = $cmd->Execute();
$res_set->MoveFirst();
my %lijst;
while ( !$res_set->{EOF} ) {
$lijst{$res_set->Fields("sAMAccountName")->{Value}} = $res_set->Fields("sAMAccountName")->{Value};
print $res_set->Fields("sAMAccountName")->{Value} . "\n";
$res_set->MoveNext();
}
$res_set->Close();
$con->Close();
sub bind_object {
my $parameter=shift;
my $moniker;
if ( uc($ENV{USERDOMAIN}) eq "III") { #ingelogd op het III domein
$moniker = (uc( substr( $parameter, 0, 7) ) eq "LDAP://" ? "" : "LDAP://").$parameter;
return (Win32::OLE->GetObject($moniker));
}
else { #niet ingelogd
my $ip="193.190.126.71"; #voor de controle thuis
$moniker = (uc( substr( $parameter, 0, 7) ) eq "LDAP://" ? "" : "LDAP://$ip/").$parameter;
my $dso = Win32::OLE->GetObject("LDAP:");
my $loginnaam = "Interim F"; #vul in
my $paswoord = "Interim F"; #vul in
return ($dso->OpenDSObject( $moniker, $loginnaam, $paswoord, ADS_SECURE_AUTHENTICATION ));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment