Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

up vote 4 down vote accepted

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"
share|improve this answer
    
Thank you, thats working. But meanwhile i had programmed it with VB.Net(see my edit). –  Tim Schmelter Jan 10 '11 at 14:59

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

net localgroup "Students" /domain >> students.txt
share|improve this answer
    
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 ö. –  Tim Schmelter Jan 10 '11 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.