title: Microsoft VBScript compilation error: Expected statement
body: <p>What is wrong with this script?</p>
  
  <pre class="lang-vb prettyprint-override"><code>Option Explicit
  
  Dim objRootDSE, strDNSDomain, adoConnection
  Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
  Dim dtmStart, dtmEnd, strStart, strEnd
  Dim strID, strFirst, strLast, strNTName
  
  dtmEnd = Now()
  dtmStart = DateAdd("d", -7, dtmEnd)
  strStart = CStr(Year(dtmStart)) _
  &amp; Right("0" &amp; CStr(Month(dtmStart)), 2) _
  &amp; Right("0" &amp; CStr(Day(dtmStart)), 2) &amp; "000000.0Z"
  strEnd = CStr(Year(dtmEnd)) _
  &amp; Right("0" &amp; CStr(Month(dtmEnd)), 2) _
  &amp; Right("0" &amp; CStr(Day(dtmEnd)), 2) &amp; "235959.0Z"
  
  ' Determine DNS domain name.
  Set objRootDSE = GetObject("LDAP://RootDSE")
  strDNSDomain = objRootDSE.Get("defaultNamingContext")
  
  ' Use ADO to search Active Directory.
  Set adoConnection = CreateObject("ADODB.Connection")
  adoConnection.Provider = "ADsDSOObject"
  adoConnection.Open "Active Directory Provider"
  
  Set adoRecordset = CreateObject("ADODB.Recordset")
  adoRecordset.ActiveConnection = adoConnection
  
  ' Search entire domain.
  strBase = "&lt;LDAP://" &amp; strDNSDomain &amp; "&gt;"
  
  'For user accounts for people created in the last week
  strFilter = "(&amp;(objectCategory=person)(objectClass=user)" _
  &amp; "(whenCreated&gt;=" &amp; strStart &amp; ")(whenCreated&lt;=" &amp; strEnd &amp; "))"
  
  ' Comma delimited list of attribute values to retrieve.
  strAttributes = "employeeID,sn,givenName,sAMAccountName"
  
  ' Construct the LDAP query.
  strQuery = strBase &amp; ";" &amp; strFilter &amp; ";" &amp; strAttributes &amp; ";subtree"
  
  ' Run the query.
  adoRecordset.Source = strQuery
  adoRecordset.Open
  
  ' Enumerate the resulting recordset.
  Do Until adoRecordset.EOF
  ' Retrieve values.
  strID = adoRecordset.Fields("employeeID").Value
  strLast = adoRecordset.Fields("sn").Value
  strFirst = adoRecordset.Fields("givenName").Value
  strNTName = adoRecordset.Fields("sAMAccountName").Value
  Wscript.Echo """" &amp; strID &amp; """,""" &amp; strLast &amp; """,""" &amp; strFirst
  &amp; """,""" &amp; strNTName &amp; """"
  adoRecordset.MoveNext
  Loop
  
  ' Clean up.
  adoRecordset.Close
  adoConnection.Close
  </code></pre>
  
  
  
  <pre><code>cscript //nologo test.vbs &gt; users.csv
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>(53, 1) Microsoft VBScript compilation error: Expected statement
  </code></pre>