Hi Andrew,

I'm not an OLE or Win32::OLE expert, but see below for a review of your code:

On Thu, 6 Sep 2012 11:23:41 +0800
andrew sison <andrew.sison...@gmail.com> wrote:

> Hello,
> 
> It has been six years since I have shifted into a new role from being
> a systems administrator to being an IT auditor. It's been a while
> since I've written my last perl script.
> 
> 
> Now I'm back here again to get some help. Basically my job now
> requires me to conduct audits on the information stored in our active
> directory.
> I've done some reading and learned that in order to automate that
> particular task using perl, I would have to use either Win32::OLE or
> Net::LDAP. So I decided to use to former. Now I am confronted with
> this simple problem which one would consider the biggest hurdle that a
> beginner programmer has to overcome for the first time. This is like
> the hello world program for me. If I can get past this, I know I can
> do anything.
> 
> The problem with the code below is that it is not able to retrieve the
> object if I type in my DN. If it's just the container OUs, then it
> seems to work fine. Let's say I would put
> "OU=CODP,OU=Users,OU=MLAPH,OU=AsiaPacific,OU=MLAROOT,DC=int,DC=mlaph,DC=com"
> instead, it would work just fine.
> 
> It doesn't work when I specify a user's distinguished name.
> 
> Unfortunately for me, I'm still looking for reference materials to
> help me with ADSI/COM programming in perl because the documentation
> for Win32::OLE doesn't really say much to help me going. Is there
> anything here you can recommend?
> 
> 
> 
> #!/usr/bin/perl
> 
> use 5.010;
> use strict;
> use warnings;

These pragmas are good. Thanks for being clueful.

> use Win32::OLE;
> 
> my $userObject = Win32::OLE->GetObject("LDAP://CN=Sison\,
> Andrew,OU=CODP,OU=Users,OU=MLAPH,OU=AsiaPacific,OU=MLAROOT,DC=int,DC=mlaph,DC=com")
> or die "Unable to retrieve object", "\n";

OK, «\,» inside a double-quoted string is equivalent to a simple comma («,»), so
why is it there? Are you trying to have a multi-line string? If so use "\n" 
inside
the string, and maybe http://perldoc.perl.org/functions/join.html to split it 
into
several shorter components. But, as it stands now, your string will have a 
comma and
a newline.

Second piece of advice is that «die "Unable to retrieve object", "\n"» should be
written as «die "Unable to retrieve object\n"» assuming you want to have
the trailing newline. I'm not sure if the die command accepts a list.

> 
> print $userObject->{displayName}, "\n";
> 

It's strange that Win32::OLE allows you to access object slots directly like 
that,
but maybe it was before accessors were as commonly accepted as they are today.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
List of Text Editors and IDEs - http://shlom.in/IDEs

Better be a tail for the lions, than the head of the jackals.
    — Pirkei Avot, 4 15

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to