Script Question - Locate New Servers

Posted on 2011-05-02
Last Modified: 2013-12-05
When I run the script below, I get " Incorrect scope argument. Use either 'subtree' or 'onelevel' "

This is how I'm running it:

C:\>cscript get_servers.vbs /date:01/01/11 / /base:"OU=Corp_Servers,DC=corp,DC=com"/scope=subtree
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Incorrect scope argument. Use either 'subtree' or 'onelevel'


What am I doing wrong?

---------------------This is the script----------------------------------------------------------

Set oRootDSE = GetObject("LDAP://RootDSE")
strFilter = "(&(objectclass=computer));"
strAttrs  = "distinguishedName;"
strScope = WScript.Arguments.Named("scope")
strBaseArg = WScript.Arguments.Named("base")
datCutOff = WScript.Arguments.Named("date")
strEmailTo = WScript.Arguments.Named("email")
strSMTPServer = ""
intSMTPPort = 25
strEmailFrom = ""
If Not(UCase(strScope) = "SUBTREE" Or UCase(strScope) = "ONELEVEL") Then
      WScript.Echo "Incorrect scope argument. Use either 'subtree' or 'onelevel'"
End If
If strBaseArg <> "" Then
      If UCase(strBaseArg) = "ROOT" Then strBase ="<LDAP://" & oRootDSE.get("defaultNamingContext") _
            & ">;" Else strBase = "<LDAP://" & strBaseArg & ">;"
      WScript.Echo strBase
      WScript.Echo "No search base given. Please specify a search base"
End If
If datCutOff = "" Then
      WScript.Echo "No date given. Please specify a search base"
End if
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
On Error Resume Next
Set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
If Err.Number <> 0 Then
      WScript.Echo "Error performing query: " & Err.Number & " - " & Err.Description
      On Error Goto 0      
      If objRs.RecordCount > 0 Then
            strEmailBody = "<font face='Verdana' size='1'><b>Report of servers created on or after " & datCutOff & "...<br>"
            strEmailBody = strEmailBody & "Searching: " & Replace(Replace(strBase,"<",""),">","") & " (" & strScope & ")</b><br><br>"
            While Not objRS.EOF
                  Set objPC = GetObject("LDAP://" & Replace(objRS.Fields(0).Value,"/","\/"))
                  strWhenCreated = objPC.whenCreated
                  If InStr(UCase(objPC.operatingSystem),"SERVER") > 0 Then
                        If DateValue(strWhenCreated) > DateValue(datCutOff) Then
                              WScript.Echo objPC.distinguishedName
                              WScript.Echo "This server was created on : " & strWhenCreated
                              WScript.Echo ""
                              strEmailBody = strEmailBody & objPC.distinguishedName & "<br>" & "This server was created on : " & strWhenCreated & "<br><br>"
                        End If
                  End If
            strEmailBody = strEmailBody & "</font>"
            Set objPC = Nothing
            'SEND THE EMAIL....
            If strEmailTo <> "" Then
                  WScript.Echo "Sending email to " & strEmailTo & "....."
                  On Error Resume Next
                  Set objMail = CreateObject("CDO.Message")
                  objMail.Subject = "Server Creation Report"
                  objMail.From = strEmailFrom
                  objMail.To = strEmailTo
                  objMail.HTMLBody = strEmailBody
                  objMail.Configuration.Fields.Item("") = 2
                  objMail.Configuration.Fields.Item("") = strSMTPServer
                  objMail.Configuration.Fields.Item("") = intSMTPPort
                  If Err.Number = 0 Then
                        WScript.Echo "Email Sent. Script Finished"
                        WScript.Echo "Error sending email: " & Err.Number & " - " & Err.Description
                  End if
                  Set objMail = Nothing
            End If
            WScript.Echo "No servers found for this search criteria"
      End If
End If
Set oRootDSE = Nothing
Set objConn = Nothing
Question by:KurtHoffeditz
    LVL 65

    Accepted Solution

    Does it help if you put a space between

    and also change the equals to a colon, so it becomes
    /base:"OU=Corp_Servers,DC=corp,DC=com" /scope:subtree


    LVL 74

    Expert Comment

    by:Glen Knight
    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now