Software >> OS >> Windows >> ADSI >> How to use windows server resource kit utility query.vbs with Perl to gather user information

Assumptions =========== - that queryad.vbs is in a directory which is in system PATH, otherwise, replace the queryad.vbs below with <fullpath>\queryad.vbs where fullpath is the full path of the directory where queryad.vbs is located. Perl script =========== use File::Basename; if($#ARGV < 0) { die "\nUsage:\n\n\ $prog displayname \n"; } $displayName = $ARGV[0]; %user = GetADInfo($displayName); print $user{"displayName"}; sub GetADInfo { my %userobj; my $displayName = shift; if ($displayName ne "") { open(CMD,"cscript queryad.vbs -u \"$displayName\" | "); while(<CMD>) { if ( /^(\w )[:](.*)$/gi ) { $par = ; $val = ; $par =~ s/^ //gi; $par =~ s/ $//gi; $val =~ s/^ //gi; $val =~ s/ $//gi; $userobj{$par} = $val; } } close(CMD); } else { print "displayName cannot be BLANK\n"; } return %userobj; }