开发者

vbscript to c# - list groups a computer is memberof (retrieve array)

I've been searching for a while here and googling for this. Can't really get my head arround it.

I need to provide an array list to another tool that I have. This is writen in C#, the best I could come up with for retreivi开发者_运维知识库ng groups for a particular computer is bellow. How would this look in C# with results being an array?

Set objComputer = GetObject("LDAP://CN=ComputerName,CN=Computers,DC=contoso,DC=com")
Set colGroups = objComputer.Groups
For Each objGroup in colGroups
    Wscript.Echo objGroup.CN
    GetNested(objGroup) 
Next

Function GetNested(objGroup)
    On Error Resume Next
    colMembers = objGroup.GetEx("memberOf")
    For Each strMember in colMembers
        strPath = "LDAP://" & strMember
        Set objNestedGroup = GetObject(strPath)
        WScript.Echo objNestedGroup.CN
        GetNested(objNestedGroup)
    Next
End Function


If using .net framework 3.5 is not an issue there's a much easier way to read out recursive group membership using the GetAuthorizationGroups method in System.DirectoryServices.AccountManagement. A PowerShell example is on my blog.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜