欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WMI脚本:计算机管理脚本范例

程序员文章站 2022-06-28 20:12:03
...
  • 更改计算机帐号属性

更改计算机帐号属性,演示如何通过脚本来更改 Active Directory 中的计算机帐号的位置属性。

脚本代码:

Set objComputer = GetObject("LDAP://CN=.,CN=Computers,DC=fabrikam,DC=com")
objComputer.Put "location", "Building 37, Floor 2, Room 2133"
objComputer.Set Info
  • 离线** Windows

使用离线方法来** Windows。需要 XP 或 Windows 2003、以及一个有效的**编号。

脚本代码:

strComputer = "."
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
  • 在线** Windows

使用在线方法来** Windows。需要 XP 或 Windows 2003、以及活动的 Internet 连接。

脚本代码:

strComputer = "."
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
  • 配置系统启动延时

将计算机配置为在启动时自动加载默认操作系统之前等待 10 秒钟(而不是默认的 30 秒钟)。

脚本代码:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")
Set colStartupCommands = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
For Each objStartupCommand In colStartupCommands
objStartupCommand.SystemStartupDelay = 10
objStartupCommand.Put_
Next
  • 获取操作系统属性

信息获取有关计算机上所安装的操作系统信息,其中包括语言种类、加密级别和内建编号等。

脚本代码:

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
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 "Boot Device: " & objOperatingSystem.BootDevice
Wscript.Echo "Build Number:" & objOperatingSystem.BuildNumber
Wscript.Echo "Build Type: " & objOperatingSystem.BuildType
Wscript.Echo "Caption: " & objOperatingSystem.Caption
Wscript.Echo "Code Set : " & objOperatingSystem.CodeSet
Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode
Wscript.Echo "Debug: " & objOperatingSystem.Debug
Wscript.Echo "Encryption Level:" & objOperatingSystem.EncryptionLevel
dtmConvertedDate.Value = objOperatingSystem.InstallDate
dtmInstallDate = dtmConvertedDate.GetVarDate
Wscript.Echo "Install Date: " & dtmInstallDate
Wscript.Echo "Licensed Users: " & objOperatingSystem.NumberOfLicensedUsers
Wscript.Echo "Organization: " & objOperatingSystem.Organization
Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage
Wscript.Echo "OS Product Suite:" & objOperatingSystem.OSProductSuite
Wscript.Echo "OS Type: " & objOperatingSystem.OSType
Wscript.Echo "Primary: " & objOperatingSystem.Primary
Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser
Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber
Wscript.Echo "Version: " & objOperatingSystem.Version
Next
  • 复制Active Directory计算机帐号

信息获取现有计算机对象属性,并将这些属性复制到通过脚本创建的新增计算机对象中。

脚本代码:

Set objCompt = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")
Set objComptCopy = objCompt.Create("computer", "cn=SEA-SQL-01")
objComptCopy.Put "sAMAccountName", "sea-sql-01"
objComptCopy.Set InfoSet
objComptTemplate = GetObject("LDAP://cn=SEA-PM-01,cn=Computers,dc=NA,dc=fabrikam,dc=com")
arrAttributes = Array("description", "location")
For Each strAttrib in arrAttributes
strValue = objComptTemplate.Get(strAttrib)
objComptCopy.Put strAttrib, strValue
Next
objComptCopy.Set Info

 

相关标签: VBScript