简体   繁体   English

如何使用VB.net按字母顺序列出广告组?

[英]How to list AD group alphabetically using VB.net?

I have created a vb.net app that within it lists the active directory groups a users computer is a member of. 我创建了一个vb.net应用程序,其中列出了用户计算机所属的活动目录组。 What I cannot do or find how to do online is how to show that list of AD groups alphabetically. 我无法在线完成或无法找到方法是如何按字母顺序显示该广告组列表。 Does anyone know how to show them in alphabetical order? 有谁知道如何按字母顺序显示它们? Here is the code I have thus far. 这是我到目前为止的代码。

Public Shared Function WorkstationADGroups(ByVal PCName As String) As String

    ' Returns list of AD Groups the comptuer is a member of
    Try
        Dim x As Integer = 1
        Dim result As String = Nothing
        Using ctx As New PrincipalContext(ContextType.Domain)
            Using p = Principal.FindByIdentity(ctx, PCName)
                If Not p Is Nothing Then
                    Dim groups = p.GetGroups()
                    Using groups
                        For Each group In groups
                            result = result & "</BR>" & x & ".     --     " & group.SamAccountName
                            x = x + 1
                        Next
                    End Using
                End If
            End Using
        End Using
        Return result
    Catch ex As Exception
        Return ex.Message
    End Try

End Function

Any help would be greatly appreciated! 任何帮助将不胜感激!

Thanks in advance. 提前致谢。

I usually go to linq for this. 我通常为此去linq。

Dim orderedGroups = (From g In Groups Order By g.SamAccountName)

Then you can loop through orderedGroups instead of Groups to get what you need. 然后,您可以遍历orderedGroups而不是Groups以获取所需的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM