Home: Perl Programming Help: Win32 Programming Help:
syntax woes



soft_king
Novice

Feb 11, 2009, 10:28 AM


Views: 7053
syntax woes

I tried running this script that I got online and I keep getting this syntax error and I don't know why. Can someone help me? I'm trying to retrieve over 1000 records from Active Directory. The code is below.

Code
use Win32::OLE 'in'; 
$colUsers = Win32::OLE->GetObject("LDAP://cn=users,dc=rallencorp,dc=com")
foreach $objUser (in $colUsers) {
print $objUser->Name,"\n";
}

I keep getting this message in cmd
syntax error at line 3, near "$objUser ( "


(This post was edited by soft_king on Feb 11, 2009, 10:31 AM)


FishMonger
Veteran / Moderator

Feb 11, 2009, 10:43 AM


Views: 7049
Re: [soft_king] syntax woes

You're missing the semi-colon on the line above it, so perl thinks the foreach line is a continuation of that line.


soft_king
Novice

Feb 17, 2009, 7:01 AM


Views: 6996
Re: [FishMonger] syntax woes

Thanks guys....
Another thing. I'm trying to create a user with perl and it I keep getting and error:

An invalid directory pathname was passed
Win32::OLE(0.1709) error 0x80005000 in METHOD/PROPERTYGET "Create". This is the code.


Code
my $fullname = $finame." ".$laname; 

my $objParent = Win32::OLE->GetObject("LDAP://OU=MyOU,dc=Mydomain,dc=ext");
my $objUser = $objParent->Create("user","cn=".$fullname);
$objUser->Put("sAMAccountName", $sAMAccountName);
$objUser->Put("userPrincipalName",$sAMAccountName."$domain");
$objUser->Put("givenName", $finame);
$objUser->Put("sn", $laname);
$objUser->Put("displayName", $finame." ".$laname);
$objUser->Put("description","description");
$objUser->SetInfo;
$objUser->SetPassword("Password");
$objUser->{AccountDisabled} = FALSE;
$objUser->SetInfo;

my $homedir = "\\\\server\\ext\\";
#my $homedrive = "";
my $profile = "\\\\server\\ext\\";


$objUser->Put("profilePath", $profile . $sAMAccountName);
$objUser->Put("homeDirectory", $homedir . $sAMAccountName);
$objUser->Put("homeDrive", "z:");
$objUser->SetInfo;
[\code]

My hunch is that something is wrong with the create line "my $objUser = $objParent->Create("user","cn=".$fullname);" but i can't figure out what it is. Can you help me?


(This post was edited by soft_king on Feb 17, 2009, 7:19 AM)