【问题标题】:How to list AD group alphabetically using VB.net?如何使用 VB.net 按字母顺序列出 AD 组?
【发布时间】:2017-11-29 16:37:47
【问题描述】:

我创建了一个 vb.net 应用程序,其中列出了用户计算机所属的活动目录组。 我不能做或在网上找不到如何做的是如何按字母顺序显示广告组列表。 有谁知道如何按字母顺序显示它们? 这是我到目前为止的代码。

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

任何帮助将不胜感激!

提前致谢。

【问题讨论】:

    标签: vb.net active-directory alphabetical


    【解决方案1】:

    我通常为此去 linq。

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

    然后你可以循环通过 orderedGroups 而不是 Groups 来获得你需要的东西。

    【讨论】:

    • 谢谢。那太容易了。哈哈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 2019-02-05
    • 2021-06-25
    相关资源
    最近更新 更多