我正在尝试编写一个VBScript,它从同一个WMI类(Win32_DiskDrive
)中提取3个不同的属性。如果您有多个驱动器,该类将提供一个数组。我想将数组中的所有结果分配给SCCM变量,但是这样做有困难,因为我之前从未做过类似的事情。
这是我的剧本:
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim objWMIService, objItem, colItems, strComputer, Index, Model, Size
Dim Index(4)
Index(0) = Index0
Index(1) = Index1
Index(2) = Index2
Index(3) = Index3
Dim Model(4)
Model(0) = Model0
Model(1) = Model1
Model(2) = Model2
Model(3) = Model3
Dim Size(4)
Size(0) = Size0
Size(1) = Size1
Size(2) = Size2
Size(3) = Size3
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Set env = CreateObject("Microsoft.SMS.TSEnvironment")
For Each objItem in colItems
Index(4) = objItem.Index
Model(4) = objItem.Model
Size(4) = objItem.Size
env("DriveIndex") = Index(4)
env("DriveModel") = Model(4)
env("DriveBytes") = Size(4)
Next
答案 0 :(得分:1)
这是一个可能的解决方案,在您的vbscript中不需要数组。它将输出一个TS变量,其后缀为驱动器号(从0开始,或者您设置的任何内容iCount
开始)。
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim objWMIService, objItem, colItems, strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Set env = CreateObject("Microsoft.SMS.TSEnvironment")
iCount = 0
For Each objItem in colItems
env("DriveIndex" & iCount) = objItem.Index
env("DriveModel" & iCount) = objItem.Model
env("DriveBytes" & iCount) = objItem.Size
iCount = iCount + 1
Next
因此,如果您有3个驱动器,您将在SCCM中得到类似的结果:
DriveIndex0 = TheIndexOf0
DriveModel0 = TheModelOf0
DriveSize0 = TheSizeOf0
DriveIndex1 = TheIndexOf1
DriveModel1 = TheModelOf1
DriveSize1 = TheSizeOf1
DriveIndex2 = TheIndexOf2
DriveModel2 = TheModelOf2
DriveSize2 = TheSizeOf2
然后您可以像往常一样在TS中引用每个变量。 %DriveIndex0%
,%DriveIndex1%
等