簡體   English   中英

如何使用VB.net按字母順序列出廣告組?

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

我創建了一個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

任何幫助將不勝感激!

提前致謝。

我通常為此去linq。

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

然后,您可以遍歷orderedGroups而不是Groups以獲取所需的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM