RE: Problems converting vbscript to perl



Found the problem, it was with the hash. $strAdsPath =
$objQueryResultSet->Fields('AdsPath')->Item; should have been
$strAdsPath = $objQueryResultSet->Fields('AdsPath')->Value;

Timothy F. Gallagher
CSC Systems Engineer

-----Original Message-----
From: Gallagher, Tim (NE) [mailto:Tim.Gallagher@xxxxxxxxxx]
Sent: Monday, April 10, 2006 12:35 PM
To: Perl Beginners
Subject: Problems converting vbscript to perl

I have a vb script example that I am trying to convert to Perl. Most of
the script is done except for the last part. Can some tell me what I am
missing? Here is the script.
Start Script
use Win32::OLE;

$strSearch = 'tim*;

$objRootDSE = Win32::OLE->GetObject('LDAP://RootDSE');
$strDomain1 = $objRootDSE->Get('DefaultNamingContext');

# Set up the ADO connection required to implement the search.
$objADOConn = Win32::OLE->new('ADODB.Connection');

$objADOConn->{Provider} = 'ADsDSOObject';
# Connect using current user credentials
$objADOConn->Open('Active Directory Provider');

$objADOCommand = Win32::OLE->new('ADODB.Command');
$objADOCommand->{ActiveConnection} = $objADOConn;

# Format search criteria using SQL syntax
$strADSQuery = 'SELECT samAccountName, givenName, sn, AdsPath FROM
\'LDAP://' . $strDomain1 . '\' WHERE samAccountName = \'' . $strSearch ..
'\'';

print $strADSQuery . "\n";


$objADOCommand->{CommandText} = $strADSQuery;

# Execute the search
$objQueryResultSet = $objADOCommand->Execute;

$intCount = 0;
while(<>)
{
$strAdsPath = $objQueryResultSet->Fields('AdsPath')->Item;
print 'The AdsPath is: ' . $strAdsPath, "\n";
print "\n";
$intCount = $intCount + 1;
$objQueryResultSet->MoveNext();
}
$objADOConn->Close();
End Script

The last part, while is not working and I cannot find out why. Here is
the VB script


Start script
strSearch = "tim.g*"

Set objRootDSE = GetObject("LDAP://RootDSE";)
strDomain1 = objRootDSE.Get("DefaultNamingContext")


'Set up the ADO connection required to implement the search.
Set objADOConn = CreateObject("ADODB.Connection")

objADOConn.Provider = "ADsDSOObject"
'Connect using current user credentials
objADOConn.Open "Active Directory Provider"


Set objADOCommand = CreateObject("ADODB.Command")
Set objADOCommand.ActiveConnection = objADOConn

'Format search criteria using SQL syntax
strADSQuery = "SELECT samAccountName, givenName, sn, AdsPath FROM
'LDAP://"; & _
strDomain1 & "' WHERE samAccountName = '" & strSearch & "'"

objADOCommand.CommandText = strADSQuery

'Execute the search
Set objQueryResultSet = objADOCommand.Execute

intCount = 0
While Not objQueryResultSet.EOF
strAdsPath = objQueryResultSet.Fields("AdsPath")
WScript.Echo("The AdsPath is: " & strAdsPath)
WScript.Echo("")
intCount = intCount + 1
objQueryResultSet.MoveNext
Wend
objADOConn.Close


end script
Timothy F. Gallagher
CSC Systems Engineer


--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>


.



Relevant Pages

  • Re: scripting newb
    ... I was able to hobble this together from another script posted by Dan ... Dim strSearch, strAdsPath, strServerName 'from search script ... Dim strDefaultDomainNC, strADSQuery 'from search script ... Set objADOConn = CreateObject ...
    (microsoft.public.scripting.vbscript)
  • Problems converting vbscript to perl
    ... I have a vb script example that I am trying to convert to Perl. ... print $strADSQuery. ... Set objADOConn = CreateObject ... intCount = intCount + 1 ...
    (perl.beginners)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)