Active Directory からコンピュータ一覧を取得してそれらのコンピュータのハードウェア情報を表示するプログラムを VBScript で書いてみた。
- DispComputerInfo.vbs
On Error Resume Next 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.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE ' ドメイン名が office.ablog.co.jp の場合 objCommand.CommandText = _ "SELECT ADsPath FROM 'LDAP://dc=office,dc=ablog,dc=co,dc=jp' WHERE " & _ "objectCategory='organizationalUnit'" Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF Set objOU = GetObject(objRecordSet.Fields("ADsPath").Value) ' Wscript.Echo objOU.distinguishedName objOU.Filter = Array("Computer") For Each objItem in objOU strComputer = objItem.CN Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set rows = objWMIService.ExecQuery("Select * from Win32_Processor",,48) For Each cols in rows Wscript.Echo strComputer & ": " & cols.Name Exit For Next Next objRecordSet.MoveNext Loop
- 実行結果
C:\>cscript //nologo DispComputerInfo.vbs HOST01: Intel(R) Xeon(R) CPU 5110 @ 1.60GHz HOST02: Intel(R) Xeon(R) CPU 5110 @ 1.60GHz ...