Consultas wmi complexas usando execquery

4

No powershell eu posso fazer uma consulta como

> get-wmiobject -query 'select * from win32_groupuser' | % {[wmi]$_.partcomponent|select domain,name,SID}

Que listará para cada wmi, o domínio, nome e sid para cada usuário.

Como eu conseguiria isso usando vbscript?

Atualmente, uso execquery :

Dim strComputer, objWMIService
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\"& strComputer & "\root\cimv2")
objWMIService.ExecQuery("select partcomponent,groupcomponent from win32_groupuser")

para a primeira parte, mas como eu incorporo o equivalente a | % {[wmi]$_.partcomponent|select domain,name,SID}

Alternativamente, como eu poderia fazer

gwmi win32_groupuser | % { [wmi]$_.partcomponent | select domain,name,sid}

usando o vbscript; como não é uma consulta, não posso usar execquery , mas tem a mesma saída da consulta original.

    
por A G 28.04.2016 / 15:17

1 resposta

0

ASSOCIATORS OF Statement

The ASSOCIATORS OF statement retrieves all instances that are associated with a particular source instance. The instances that are retrieved are referred to as the endpoints. Each endpoint is returned as many times as there are associations between it and the source object.

Script de amostra :

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
    
por 21.12.2017 / 02:41