WMI 脚本列出当前计算机的成员资格?

WMI 脚本列出当前计算机的成员资格?

我在 2003R2 和 2008R2 上托管了一个 AD,我想在用户使用域计算机(例如 compA)登录并在脚本内执行某些操作时检查该计算机(例如 compA)的成员身份。我认为 WMI 可能有用,但我无法找到正确的查询来获取相关计算机帐户的组列表。有什么想法吗?

答案1

获取 WmiObject win32_ComputerSystem | 格式列表域角色

        0"Stand Alone Workstation"
        1"Member Workstation"
        2"Stand Alone Server"
        3"Member Server"
        4"Back-up Domain Controller"
        5"Primary Domain Controller"

答案2

这是我修改的脚本本网站。我还没有测试过代码,但它看起来不错。

Option Explicit
Dim objNetwork, strDomain, strComputer, objComputer, objGroup, strGroupMemberships
Dim arrGroupMemberships

' Get the domain and username from the WScript.Network object
Set objNetwork = CreateObject("WScript.Network")
strDomain = objNetwork.UserDomain
strComputer = objNetwork.ComputerName

' Instanciate the user object from the data above
Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer)

' Run through the users groups and put them in the string
For Each objGroup In objComputer.Groups
    strGroupMemberships = strGroupMemberships & objGroup.Name & ","
Next

arrGroupMemberships = Split(strGroupMemberships, ",")

' Loop through array to get groups that this computer is a member of

如果您现在还没有解决这个问题,这应该会让您朝着正确的方向前进。

相关内容