title: VB.NET - How to Convert SID to Group Name with Active Directory
body: <p>Using VB.NET, How do you Convert the sid to Group Name with Active Directory? </p>
  
  <p>example: I need to get "group_test" and not "S-1-5-32-544"</p>
  
  <p>The code I'm using is:</p>
  
  <pre><code>Public ReadOnly Property Groups As IdentityReferenceCollection
      Get
  
          Dim irc As IdentityReferenceCollection
          Dim ir As IdentityReference
          irc = WindowsIdentity.GetCurrent().Groups
          Dim strGroupName As String
  
          For Each ir In irc
              Dim mktGroup As IdentityReference = ir.Translate(GetType(NTAccount))
              MsgBox(mktGroup.Value)
              Debug.WriteLine(mktGroup.Value)
              strGroupName = mktGroup.Value.ToString
  
          Next
  
          Return irc
  
      End Get
  End Property
  </code></pre>
  
  <p>or something like this? </p>
  
  <pre><code>        currentUser = WindowsIdentity.GetCurrent()
  
          For Each refGroup As IdentityReference In currentUser.Groups
  
              Dim acc As NTAccount = TryCast(refGroup.Translate(GetType(NTAccount)), NTAccount)
              If AdminGroupName = acc.Value Then
                  ret = "999"
              End If
              If UsersGroupName = acc.Value Then
                  ret = "1"
              End If
  </code></pre>
  
  <p>how would u adapt it to this code? (if user is in xx group, show xx group on drop down list) </p>
  
  <pre><code>        For Each UserGroup In WindowsIdentity.GetCurrent().Groups
              If mktGroup.Value = "BIG" Then
                  Dim Company = ac1.Cast(Of MarketingCompany).Where(Function(ac) ac.MarketingCompanyShort = "BIG").FirstOrDefault
                  If Company IsNot Nothing Then
                      marketingCo.Items.Add(String.Format("{0} | {1}", Company.MarketingCompanyShort, Company.MarketingCompanyName))
                  End If
              End If
          Next
  </code></pre>