4

i'm trying to print all users of a group "Students" to a Textfile "Students.txt".

I'm not in a domain, so this does not work:

net group "Students" >>  students.txt

because i get following:

This command can be used only on a Windows Domain Controller.

Thank you in advance

If anybody is interested in a VB.Net solution, i've programmed a Winform solution with a multiline Textbox to copy/paste the members (anyway, thanks for your help):

  Imports System.DirectoryServices 'first add a refernce to it from .Net Tab'

....

  Public Function MembersOfGroup(ByVal GroupName As String) As List(Of DirectoryServices.DirectoryEntry)
        Dim members As New List(Of DirectoryServices.DirectoryEntry)
        Try
            Using search As New DirectoryServices.DirectoryEntry("WinNT://./" & GroupName & ",group")
                For Each member As Object In DirectCast(search.Invoke("Members"), IEnumerable)
                    Dim memberEntry As New DirectoryEntry(member)
                    members.Add(memberEntry)
                Next
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        Return members
    End Function

    Private Sub TxtGroup_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtGroup.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.TxtGroupMembers.Text = String.Empty
            If Me.TxtGroup.Text.Length <> 0 Then
                Dim members As List(Of DirectoryServices.DirectoryEntry) = MembersOfGroup(Me.TxtGroup.Text)
                For Each member As DirectoryServices.DirectoryEntry In members
                    Me.TxtGroupMembers.Text &= member.Name & vbCrLf
                Next
            End If
        End If
    End Sub

2 Answers 2

4

If you can use PowerShell then this should do the trick (works on local computer, change the $GroupName variable and output file path according to your needs):

$GroupName = "Administrators"
$GroupMembers = @()
$Server = $env:computername
$Group= [ADSI]"WinNT://$Server/$GroupName,group"
$Members = @($Group.psbase.Invoke("Members"))
$Members | ForEach-Object { $GroupMembers += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) }
Write-Output $GroupMembers | out-File "C:\somefolder\somefile.txt"
1
  • Thank you, thats working. But meanwhile i had programmed it with VB.Net(see my edit). Jan 10, 2011 at 14:59
2

You could try using net localgroup with the /domain parameter:

net localgroup "Students" /domain >> students.txt
1
  • This is working too if i remove /domain, thank you. Besides Siim K's solution has unlike this no problems with special chars like german ö. Jan 10, 2011 at 15:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .