Creating and Running a Simple Script

To ensure that you can create and run a simple SMS script, this section steps you through the process of creating and running a script that changes the name of a collection.

To create and run a simple SMS script

  1. Outline what you want to accomplish with the script. In this case, the goal is to connect to SMS, find the "All Windows NT Systems" collection, and change its name to "All Windows NT Systems (any version, any type)".

  2. Open Notepad, add the sample script shown in Sample C.1, and then save the file as C:\First.vbs.

    Sample C.1 First.vbs - a sample script

    Set loc = CreateObject("WbemScripting.SWbemLocator")
    Set WbemServices = loc.ConnectServer( , "root\SMS\site_B2K")
    Set Object = WbemServices.Get("SMS_Collection.CollectionID='SMS000CS'")
    Wscript.Echo Object.CollectionID, Object.Name
    Object.Name="All Windows NT Systems (any version, any type)"object.Put_
    

    In this example, because you have a script that is close to what you require, you do not have to remove any of the script's contents.

  3. If you are working on the site server, the only thing you have to change is the site code. Change B2K to the site code for your test site server (and change it to the value for your production site server when the script is ready for production). If you are working on a computer other than a primary site server, change the second line to include the primary site server name and possibly a user name and password, such as shown in the following example.

    Set WbemServices = loc.ConnectServer( "servername", "root\SMS\site_B2K" "username", "password" )
    
  4. Save the file again.

  5. In the SMS Administrator console, look for the All Windows NT Systems collection, and then verify that you have a collection with this exact name. (Testing should always include verifying the state of the object before the script is run.)

  6. Click the Start button, point to Programs, point to Accessories, and then click Command Prompt.

  7. At the command prompt, type Cscript C:\First.vbs.

  8. If there are any errors, correct them, save the file, and go back to step 6.

  9. In the SMS Administrator console, click Refresh.

  10. In the SMS Administrator console, look for the All Windows NT Systems collection. The name should now include "(any version, any type)". If it does not, correct any errors, save the file, and go back to step 6. Errors at this level are less obvious than the errors in step 10. They are either errors in the logic of the script (as opposed to its syntax) or problems outside of the script that prevent SMS from working properly.

  11. If you are working on a computer running Windows 2000, Windows XP, or any operating system in the Windows Server 2003 family, you can try running the script by double-clicking it in Windows Explorer or by just entering the file name at the command prompt.

    This second execution of the script will not change the collection name (unless you write another script to change the collection name back to normal and run that script first). It will, however, allow you to see that scripts can be run from places other than the command prompt.

Note

  • If the site that you are testing in is a child site, the collection name in this example will be overwritten the next time the parent site sends an update for the collection.
For More Information

Did you find this information useful? Please send your suggestions and comments about the documentation to smsdocs@microsoft.com.