Introduction to VBScript Echo
Confirmation Message
The purpose of the WSH pop-up message is to let you know that the script
has completed successfully. It can also give you valuable extra information,
for instance, the number of objects created, and the container where they are
'born'.
This is a very basic script, which fits with my aim to start simply.
Prerequisites
This script is suitable for most Windows clients
going right back to XP, W2K, even NT 4.0 and Win 9x.
Instructions for Creating your WMI Script
Copy and paste the example script below into notepad or a VBScript editor.
Decide the name of the machine on line 8.
Save the file with a .vbs extension, for example: Simple1.vbs.
Double click Simple1.vbs and check the UserName.
Script to Demonstrate the Basics of VBScript Echo
' Simple1.vbs ' Sample VBScript Echo to display the ComputerName ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 1.5 - November 2010 '
--------------------------------------------------' Option Explicit Dim strComputer strComputer = "LocalHost" WScript.Echo "Computer: " _ & strComputer WScript.Quit ' End of VBScript
example.
Example
2: Script to Test WScript.echo
If we use the script below as our 'vehicle' then we can experiment with
WScript.Echo messages to confirm that the script worked properly.
What the script does is to create ten users in an OU called BulkGuy.
It should work in any domain. If you do not have a domain available
then adapt the WSCript.echo method to a simpler script.
' VBScript to create an OU called BulkGuy
' VBScript then creates 10 Users in OU BulkGuy
' Guy Thomas - January 2004
Dim objRoot, objDomain, objOU, objContainer
Dim strName
Dim intUser
strName ="BulkGuy"
Set objRoot = GetObject("LDAP://rootDSE")
Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objOU=objDomain.Create("organizationalUnit", "ou=BulkGuy")
objOU.Put "Description", "Guy's Bulk Users OU"
objOU.SetInfo
Set objContainer = GetObject("LDAP://OU=BulkGuy," & _
objRootDSE.Get("defaultNamingContext"))
For account = 1 To 10
Set objLeaf = objContainer.Create("User", "cn=" & strName & account)
objLeaf.Put "sAMAccountName", strName & account
objLeaf.SetInfo
intUser = intUser +1
Next
WScript.Echo "10 Users created BulkGuy" WScript.quit
Using the WScript.Echo method to pop-up a message.
' Plain String message WScript.Echo "10 Users created BulkGuy"
Note 1: It is the command .Echo that WScript actually uses to produces a message box.
WScript.quit has a very different meaning.
Guy
Recommends: Permissions Analyzer - Free Active Directory Tool
I like the
Permissions Monitor because it enables me to see quickly WHO has permissions
to do WHAT. When you launch this tool it analyzes a users effective NTFS
permissions for a specific file or folder, takes into account network share
access, then displays the results in a nifty desktop dashboard!
Think of all the frustration that this free utility saves when you are
troubleshooting authorization problems for users access to a resource.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, SolarWinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.