在 powershell 中我可以执行类似
> get-wmiobject -query 'select * from win32_groupuser' | % {[wmi]$_.partcomponent|select domain,name,SID}
它将列出每个 wmi、每个用户的域、名称和 sid。
我如何使用 vbscript 来实现这一点?
我目前使用execquery
:
Dim strComputer, objWMIService
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\cimv2")
objWMIService.ExecQuery("select partcomponent,groupcomponent from win32_groupuser")
对于第一部分,但我如何将等同于| % {[wmi]$_.partcomponent|select domain,name,SID}
或者我该怎么做
gwmi win32_groupuser | % { [wmi]$_.partcomponent | select domain,name,sid}
使用 vbscript;因为它不是一个查询,所以我不能使用execquery
,但它具有与原始查询相同的输出。
答案1
该
ASSOCIATORS OF
语句检索与特定源实例相关联的所有实例。检索到的实例称为端点。每个端点的返回次数与它与源对象之间的关联次数相同。
示例脚本:
option explicit
Dim sResult, strComputer, objWMIService, group, groups, user, users
sResult = ""
strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set groups = objWMIService.ExecQuery( "SELECT * FROM Win32_Group" )
For Each group in groups
Set users = objWMIService.ExecQuery( _
"Associators of {Win32_Group.Domain='" & group.Domain _
& "',Name='" & group.Name & "'} " _
& "Where AssocClass = Win32_GroupUser ResultRole = PartComponent")
For Each user in users
sResult = sResult & vbNewLine & group.Domain & " " & group.Name _
& vbTab & user.Name & vbTab & user.SID
Next
Next
Wscript.Echo sResult