Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 VSarkiss (Monsignor) on Nov 30, 2004 at 21:55 UTC
      Thank you, Eval worked perfectly.
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 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).
    --Stevie-O
    $"=$,,$_=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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2019-07-24 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (32 votes). Check out past polls.

    Notices?