System Administration Scripting GuideScript Repository Version 1.1, August 2002 The scripts included in this help file are likely to appear in the forthcoming System Administration Scrip
Trang 1
System Administration
Scripting Guide Script Repository
Trang 2
System Administration Scripting Guide
Script Repository
Version 1.1, August 2002
The scripts included in this help file are likely to appear in the forthcoming System Administration
Scripting Guide, which will ship as part of the Windows NET Server Resource Kit In the Scripting
Guide itself, each script will be explained in step-by-step fashion, and instructional material willhelp you learn how to modify these scripts to suit your unique individual needs In addition, thebook will also teach you how to write your own scripts using VBScript, WMI, ADSI, and otherMicrosoft Scripting technologies
Most of the scripts are designed to run with either Windows 2000, Windows XP, or Windows NETServer Scripts that are not designed to run on all these platforms include a brief note indicatingwhich versions of Windows are required
To use the scripts, copy the appropriate script code, paste it into Notepad or another text editor,and save the file with a vbs file extension
For more information about these scripts or about the book, contact the Scripting Guide team at
scripter@microsoft.com
A Note About the WMI Scripts
Most of the WMI scripts in this repository create a variable named strComputer, and then set thevalue of that variable to "." Thus, the scripts generally include this line:
strComputer = "."
This causes the script to run against the local computer This is due to the way that the script hasbeen composed, and the fact that WMI views a computer named "." as being the local computer Ifyou want to run the script against a remote computer, simply replace the "." with the name of theremote computer, surrounded by double quotation marks For example, this line of code runs thescript against a remote computer named PrintServer1:
strComputer = "PrintServer1"
This is the only change you need to make in order to run the WMI scripts against a remote
computer Bear in mind, however, that you will need to have administrative rights on the remotecomputer in order for the script to succeed In addition, WMI must be installed both on the localcomputer and on the remote computer
Trang 3System Administration Scripting Guide
Disclaimer
The SOFTWARE supplied in this download site is not supported under any Microsoft standardsupport program or service You can, however, report issues and bugs by sending e-mail toscripter@microsoft.com Microsoft will, at its sole discretion, address issues and bugs reported inthis manner, and responses are not guaranteed
The SOFTWARE (including instructions for its use and all printed and online documentation) isprovided AS IS without warranty of any kind Microsoft further disclaims all implied warrantiesincluding, without limitation, any implied warranties of merchantability or of fitness for a particularpurpose The entire risk arising out of the use or performance of the SOFTWARE and
documentation remains with you
In no event shall Microsoft, its authors, or anyone else involved in the creation, production, ordelivery of the SOFTWARE be liable for any damages whatsoever (including, without limitation,damages for loss of business profits, business interruption, loss of business information, or otherpecuniary loss) arising out of the use of or inability to use the SOFTWARE or documentation, even
if Microsoft has been advised of the possibility of such damages
Important
These scripts have not been localized: they are written and tested in English only Using thesescripts with a different language version of Windows might produce unpredictable results
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 4Activate Windows Offline
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colWindowsProducts = objWMIService.ExecQuery _
("SELECT * FROM Win32_WindowsProductActivation")
For Each objWindowsProduct In colWindowsProducts
objWindowsProduct.ActivateOffline("1234-1234")
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 5Activate Windows Online
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colWindowsProducts = objWMIService.ExecQuery _
("SELECT * FROM Win32_WindowsProductActivation")
For Each objWindowsProduct In colWindowsProducts
objWindowsProduct.ActivateOnline()
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 6Change Computer Account Attributes
Trang 7Configure System Startup Delay
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colStartupCommands = objWMIService.ExecQuery _
("SELECT * FROM Win32_ComputerSystem")
For Each objStartupCommand In colStartupCommands
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 8Configure WMI Settings
Description
Configures WMI backup interval and logging level
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colWMISettings = objWMIService.ExecQuery _
("SELECT * FROM Win32_WMISetting")
For Each objWMISetting In colWMISettings
Trang 9Create a Computer Account
Const ADS_UF_PASSWD_NOTREQD = &h0020
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Computers," & _
objRootDSE.Get("defaultNamingContext"))
Set objComputer = objContainer.Create("Computer", "cn=" & strComputer)
objComputer.Put "sAMAccountName", strComputer & "$"
objComputer.Put "userAccountControl", _
ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNTobjComputer.SetInfo
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 10Create a Computer Account For a User
Dim strComputer, strComputerUser
Dim objRootDSE, objContainer, objComputer
Dim objSecurityDescriptor, objDACL
Dim objACE1, objACE2, objACE3, objACE4, objACE5
Dim objACE6, objACE7, objACE8, objACE9
strComputer = "atl-pro-002"
strComputerUser = "fabrikam\lewjudy"
' ADS_USER_FLAG_ENUM
Const ADS_UF_PASSWD_NOTREQD = &h0020
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000
' ADS_ACETYPE_ENUM
Const ADS_ACETYPE_ACCESS_ALLOWED = &h0
Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &h5
' ADS_FLAGTYPE_ENUM
Const ADS_FLAG_OBJECT_TYPE_PRESENT = &h1
' ADS_RIGHTS_ENUM
Const ADS_RIGHT_GENERIC_READ = &h80000000
Const ADS_RIGHT_DS_SELF = &h8
Const ADS_RIGHT_DS_WRITE_PROP = &h20
Const ADS_RIGHT_DS_CONTROL_ACCESS = &h100
'controlAccessRight rightsGuid values
Const ALLOWED_TO_AUTHENTICATE = "{68B1D179-0D15-4d4f-AB71-46152E79A7BC}"Const RECEIVE_AS = "{AB721A56-1E2f-11D0-9819-00AA0040529B}"Const SEND_AS = "{AB721A54-1E2f-11D0-9819-00AA0040529B}"Const USER_CHANGE_PASSWORD = "{AB721A53-1E2f-11D0-9819-00AA0040529b}"Const USER_FORCE_CHANGE_PASSWORD = "{00299570-246D-11D0-A768-00AA006E0529}"Const USER_ACCOUNT_RESTRICTIONS = "{4C164200-20C0-11D0-A768-00AA006E0529}"Const VALIDATED_DNS_HOST_NAME = "{72E39547-7B18-11D1-ADEF-00C04FD8D5CD}"Const VALIDATED_SPN = "{F3A64788-5306-11D1-A9C5-0000F80367C1}"Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Computers," & _
objRootDSE.Get("defaultNamingContext"))
Set objComputer = objContainer.Create("Computer", "cn=" & strComputer)objComputer.Put "sAMAccountName", strComputer & "$"
Trang 11objComputer.Put "userAccountControl", _
ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNTobjComputer.SetInfo
Set objSecurityDescriptor = objComputer.Get("ntSecurityDescriptor")
Set objDACL = objSecurityDescriptor.DiscretionaryAcl
Set objACE1 = CreateObject("AccessControlEntry")
objACE1.Trustee = strComputerUser
objACE1.AccessMask = ADS_RIGHT_GENERIC_READ
objACE1.AceFlags = 0
objACE1.AceType = ADS_ACETYPE_ACCESS_ALLOWED
' objACE2 through objACE6: Extended Rights
Set objACE2 = CreateObject("AccessControlEntry")
' objACE7: Property Sets
Set objACE7 = CreateObject("AccessControlEntry")
objACE7.Trustee = strComputerUser
objACE7.AccessMask = ADS_RIGHT_DS_WRITE_PROP
objACE7.AceFlags = 0
objACE7.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 12objACE7.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE7.ObjectType = USER_ACCOUNT_RESTRICTIONS
' objACE8 and objACE9: Validated Rights
Set objACE8 = CreateObject("AccessControlEntry")
Trang 13Delete a Computer Account
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 14Disable a Global Catalog Server
If intOptions And NTDSDSA_OPT_IS_GC Then
objDsRoot.Put "options", intOptions Xor NTDSDSA_OPT_IS_GC
objDsRoot.SetInfo
End If
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 15Enable a Global Catalog Server
If (intOptions And NTDSDSA_OPT_IS_GC) = FALSE Then
objDsRoot.Put "options", intOptions Or NTDSDSA_OPT_IS_GC
objDsRoot.SetInfo
End If
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 16Enumerate Computer Account Attributes
Description
Demonstration script that retrieves the location and description attributes for a computer account in ActiveDirectory
Script Code
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
strComputer = "atl-dc-01"
Set objComputer = GetObject("LDAP://CN=" & strComputer & _
",CN=Computers,DC=fabrikam,DC=com")
strLocation = objComputer.Get("location")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "The location has not been set for this computer."
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "The description has not been set for this computer."
Trang 17Enumerate Computer Accounts in Active Directory
Description
Returns the name and location for all the computer accounts in Active Directory
Script Code
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=fabrikam,DC=com' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 18Enumerate Computer Startup Commands
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colStartupCommands = objWMIService.ExecQuery _
("Select * from Win32_StartupCommand")
For Each objStartupCommand in colStartupCommands
Wscript.Echo "Command: " & objStartupCommand.Command
Wscript.Echo "Description: " & objStartupCommand.Description
Wscript.Echo "Location: " & objStartupCommand.Location
Wscript.Echo "Name: " & objStartupCommand.Name
Wscript.Echo "SettingID: " & objStartupCommand.SettingID
Wscript.Echo "User: " & objStartupCommand.User
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 19Enumerate Computer Startup Options
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colStartupCommands = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objStartupCommand in colStartupCommands
Wscript.Echo "Reset Boot Enabled: " & _
objStartupCommand.AutomaticResetBootOption
Wscript.Echo "Reset Boot Possible: " & _
objStartupCommand.AutomaticResetCapability
Wscript.Echo "Boot State: " & objStartupCommand.BootupState
Wscript.Echo "Startup Delay: " & objStartupCommand.SystemStartupDelay For i = 0 to Ubound(objStartupCommand.SystemStartupOptions)
Wscript.Echo "Startup Options: " & _
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 20Enumerate Installed Hot Fixes
Description
Returns a list of all the hot fixes installed on a computer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colQuickFixes = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
Wscript.Echo "Computer: " & objQuickFix.CSName
Wscript.Echo "Description: " & objQuickFix.Description
Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID
Wscript.Echo "Installation Date: " & objQuickFix.InstallDate
Wscript.Echo "Installed By: " & objQuickFix.InstalledBy
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 21Enumerate Installed Software
Description
Returns a list of software that was installed on a computer using Windows Installer
Script Code
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _ & "Version"
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate2 & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 22Enumerate Installed Software Features
Description
Returns a list of features for all the software that was installed on a computer using Windows Installer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colFeatures = objWMIService.ExecQuery _
("Select * from Win32_SoftwareFeature")
For each objFeature in colfeatures
Wscript.Echo "Accesses: " & objFeature.Accesses
Wscript.Echo "Attributes: " & objFeature.Attributes
Wscript.Echo "Caption: " & objFeature.Caption
Wscript.Echo "Description: " & objFeature.Description
Wscript.Echo "Identifying Number: " & objFeature.IdentifyingNumber
Wscript.Echo "Install Date: " & objFeature.InstallDate
Wscript.Echo "Install State: " & objFeature.InstallState
Wscript.Echo "LastUse: " & objFeature.LastUse
Wscript.Echo "Name: " & objFeature.Name
Wscript.Echo "ProductName: " & objFeature.ProductName
Wscript.Echo "Vendor: " & objFeature.Vendor
Wscript.Echo "Version: " & objFeature.Version
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 23Enumerate Recovery Configuration Options
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colRecoveryOptions = objWMIService.ExecQuery _
("Select * from Win32_OSRecoveryConfiguration")
For Each objOption in colRecoveryOptions
Wscript.Echo "Auto reboot: " & objOption.AutoReboot
Wscript.Echo "Debug File Path: " & objOption.DebugFilePath
Wscript.Echo "Debug Info Type: " & objOption.DebugInfoType
Wscript.Echo "Kernel Dump Only: " & objOption.KernelDumpOnly
Wscript.Echo "Name: " & objOption.Name
Wscript.Echo "Overwrite Existing Debug File: " & _
objOption.OverwriteExistingDebugFile
Wscript.Echo "Send Administrative Alert: " & objOption.SendAdminAlert Wscript.Echo "Write Debug Information: " & objOption.WriteDebugInfo Wscript.Echo "Write to System Log: " & objOption.WriteToSystemLog
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 24Enumerate WMI Settings
Description
Returns a list of WMI settings as configured on a computer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colWMISettings = objWMIService.ExecQuery _
("Select * from Win32_WMISetting")
For Each objWMISetting in colWMISettings
Wscript.Echo "Default namespace: " & _
objWMISetting.ASPScriptDefaultNamespace
Wscript.Echo "Backup interval: " & objWMISetting.BackupInterval
Wscript.Echo "Last backup: " & objWMISetting.BackupLastTime
Wscript.Echo "Build version: " & objWMISetting.BuildVersion
Wscript.Echo "Repository directory: " & _
objWMISetting.DatabaseDirectory
Wscript.Echo "Enable events: " & objWMISetting.EnableEvents
Wscript.Echo "High threshold on client objects: " & _
Wscript.Echo "Logging folder: " & objWMISetting.LoggingDirectory
Wscript.Echo "Logging level: " & objWMISetting.LoggingLevel
Wscript.Echo "Low threshold on client objects: " & _
Trang 25Identify a Global Catalog Server
If intOptions And NTDSDSA_OPT_IS_GC Then
WScript.Echo strComputer & " is a global catalog server."
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 26Identify Computer Chassis Type
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
For i = Lbound(objChassis.ChassisTypes) to Ubound(objChassis.ChassisTypes) Wscript.Echo objChassis.ChassisTypes(i)
Next
Next
The System Administration Scripting Guide , part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 27Identify Computer Roles
Description
Returns the basic role (domain controller, member server, workstation, etc.) for a computer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colComputers = objWMIService.ExecQuery _
("Select DomainRole from Win32_ComputerSystem")
For Each objComputer in colComputers
Select Case objComputer.DomainRole
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 28Identify Computer Roles Using Services
Description
Indicates whether SQL Server is running on a computer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'MSSQLServer'")
If colServices.Count > 0 Then
For Each objService in colServices
Wscript.Echo "SQL Server is " & objService.State & "."
Trang 29Identify FSMO Roles
Set objNtds = GetObject("LDAP://" & strSchemaMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Forest-wide Schema Master FSMO: " & objComputer.Name
Set objNtds = Nothing
Set objComputer = Nothing
' Domain Naming Master
Set objPartitions = GetObject("LDAP://CN=Partitions," & _
objRootDSE.Get("configurationNamingContext"))strDomainNamingMaster = objPartitions.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strDomainNamingMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Forest-wide Domain Naming Master FSMO: " & objComputer.NameSet objNtds = Nothing
Set objComputer = Nothing
' PDC Emulator
Set objDomain = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext"))strPdcEmulator = objDomain.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strPdcEmulator)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's PDC Emulator FSMO: " & objComputer.Name
Set objNtds = Nothing
Set objComputer = Nothing
' RID Master
Set objRidManager = GetObject("LDAP://CN=RID Manager$,CN=System," & _
objRootDSE.Get("defaultNamingContext"))
strRidMaster = objRidManager.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strRidMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's RID Master FSMO: " & objComputer.Name
Set objNtds = Nothing
Set objComputer = Nothing
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 30' Infrastructure Master
Set objInfrastructure = GetObject("LDAP://CN=Infrastructure," & _
objRootDSE.Get("defaultNamingContext"))strInfrastructureMaster = objInfrastructure.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strInfrastructureMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's Infrastructure Master FSMO: " & objComputer.Name
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 31Identify the Latest Installed Service Pack
Description
Returns the last service pack to be installed on a computer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 32Identify the Operating System
Description
Returns the name and version number of the operating system installed on a computer
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption & " " & objOperatingSystem.VersionNext
The System Administration Scripting Guide , part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 33Identify Windows Product Activation Status
Description
Returns product activation information for a computer Requires Windows XP or Windows NET Server
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colWPA = objWMIService.ExecQuery _
("Select * from Win32_WindowsProductActivation")
For Each objWPA in colWPA
Wscript.Echo "Activation Required: " & objWPA.ActivationRequired
Wscript.Echo "Description: " & objWPA.Description
Wscript.Echo "Product ID: " & objWPA.ProductID
Wscript.Echo "Remaining Evaluation Period: " & _
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 34Identifying Processor Type
Wscript.Echo "This is an x86 computer."
ElseIf objProcessor.Architecture = 1 Then
Wscript.Echo "This is a MIPS computer."
ElseIf objProcessor.Architecture = 2 Then
Wscript.Echo "This is an Alpha computer."
ElseIf objProcessor.Architecture = 3 Then
Wscript.Echo "This is a PowerPC computer."
ElseIf objProcessor.Architecture = 6 Then
Wscript.Echo "This is an ia64 computer."
Trang 35Install Software on a Remote Computer
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer _
("WebServer", "root\cimv2", "fabrikam\administrator", _
"password", , "kerberos:WebServer")
objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegateSet objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\atl-dc-02\scripts\1561_lab.msi",,True)Wscript.Echo errReturn
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 36Install Software on the Local Computer
Description
Installs a hypothetical software program (using a Windows Installer package) on a local computer
Script Code
Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("c:\scripts\database.msi", , ALL_USERS)
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
Trang 37Inventory Computer Hardware
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colMice = objWMIService.ExecQuery _
("Select * from Win32_PointingDevice")
For Each objMouse in colMice
Wscript.Echo "Hardware Type: " & objMouse.HardwareType
Wscript.Echo "Number of Buttons: " & objMouse.NumberOfButtons
Wscript.Echo "Status: " & objMouse.Status
Wscript.Echo "PNP Device ID: " & objMouse.PNPDeviceID
Next
The System Administration Scripting Guide, part of the Windows NET Server Resource Kit For more information, contact
scripter@microsoft.com.
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 38Join Computer to a Domain
Trang 39Modify Recovery Configuration Options
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colRecoveryOptions = objWMIService.ExecQuery _
("Select * from Win32_OSREcoveryConfiguration")
For Each objOption in colRecoveryOptions
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER By THETA-SOFTWARE
Trang 40Monitor Changes in Computer Power Status
Description
Issues an alert if a computer changes power state (for example, enters or leaves suspend mode)
Script Code
Set colMonitoredEvents = GetObject("winmgmts:")._
ExecNotificationQuery("Select * from Win32_PowerManagementEvent")