Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

AD User Exist?

by helmex (Initiate)
on Nov 30, 2004 at 20:58 UTC ( #411282=perlquestion: print w/replies, xml ) Need Help??

helmex has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am trying to find a way to check if a user exists in specific Originization Unit. I cannot use a typical if statement on my list of users:

$path='cn=username,ou=mybase_ou,dc=computer,dc=com'; if (my $objUser = Win32::OLE->GetObject("LDAP://" . $path)){ }

Because the program will die as soon as I reach a username that does not exists, because the bind fails. Any help or suggestions would be much appreciated

Replies are listed 'Best First'.
Re: AD User Exist?
by boo_radley (Parson) on Nov 30, 2004 at 21:12 UTC
    When I had to do this, I did it with Win32::AD::User.
    $user=Win32::AD::User->new("WinNT://DOMAIN/username,user","username"); $user->get_info(); print join "\n",$user->get_groups();
    if $user's undef, there's no account there.
Re: AD User Exist?
by VSarkiss (Monsignor) on Nov 30, 2004 at 21:55 UTC
      Thank you, Eval worked perfectly.
Re: AD User Exist?
by Stevie-O (Friar) on Dec 01, 2004 at 00:29 UTC
    My suggestion is similar to VSarkiss's:
    my $objUser = eval { Win32::OLE->GetObject("LDAP://$path") }; # now, $objUser will either be an object (if it worked), or # undef (if it didn't work).
    $"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc
Re: AD User Exist?
by ekkis (Initiate) on Nov 30, 2004 at 21:09 UTC
    wrap the stmt in a try?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://411282]
Approved by atcroft
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2020-08-12 06:17 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (64 votes). Check out past polls.