ullmanneric
asked on
Powershell script to gather users in a domain group and export to a csv
I am trying to create a powershell script that will pull a list of groups from a text file and then output the users in those groups to a csv file for each group.
ASKER
That one does not work exactly what I want since I only want users names in a particular group so in theory I want the report to list the group name and then the users in that group and that is it. The groups names should come from a text file
sorry forgott o add something
$Groups = Get-content c:\groups.txt
$Groups | Foreach {
Get-qadgroupmember $_ | Select samaccountname | export-csv "C:\$($_.)csv"
}
$Groups = Get-content c:\groups.txt
$Groups | Foreach {
Get-qadgroupmember $_ | Select samaccountname | export-csv "C:\$($_.)csv"
}
ASKER
It doesnt work when I put two groups in the groups.txt file the last group to ruin overrides the first group in the csv file so I dont get the info I need
ASKER
SO I need the account name and Full name fields also I need each group to be lested right now I am running two groups to test test1 and test2 users in test2 are overiding the csv file so basically the last group is overriding everything I need all the groups listed whether they are seperate tabs or something
the csv files should be the name of the groups in the text file. So if you have group1 and group2 you should have two file group1.csv and group2.csv
for the full names do this,
$Groups = Get-content c:\groups.txt
$Groups | Foreach {
Get-qadgroupmember $_ | Select name, samaccountname | export-csv -Delimiter ; "C:\$($_.)csv"
}
for the full names do this,
$Groups = Get-content c:\groups.txt
$Groups | Foreach {
Get-qadgroupmember $_ | Select name, samaccountname | export-csv -Delimiter ; "C:\$($_.)csv"
}
ASKER
yeah that is not working that way
ASKER
It is basically giving an error
ASKER
Missing property name after reference operator.
At line:2 char:4
+ $_. <<<<
+ CategoryInfo : ParserError: (.:String) [], ParentContainsErrorRecordE xception
+ FullyQualifiedErrorId : MissingPropertyName
[PS] H:\>
At line:2 char:4
+ $_. <<<<
+ CategoryInfo : ParserError: (.:String) [], ParentContainsErrorRecordE
+ FullyQualifiedErrorId : MissingPropertyName
[PS] H:\>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
still no go
Export-Csv : Missing an argument for parameter 'Delimiter'. Specify a parameter of type 'System.Char' and try again.
At line:2 char:76
+ Get-qadgroupmember $_ | Select name, samaccountname | export-csv -Delimiter <<<< ; "C:\$($_).csv"
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft. PowerShell .Commands. ExportCsvC ommand
C:\g-lan infrastructure.csv
Export-Csv : Missing an argument for parameter 'Delimiter'. Specify a parameter of type 'System.Char' and try again.
At line:2 char:76
+ Get-qadgroupmember $_ | Select name, samaccountname | export-csv -Delimiter <<<< ; "C:\$($_).csv"
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft. PowerShell .Commands. ExportCsvC ommand
C:\g-group.csv
Export-Csv : Missing an argument for parameter 'Delimiter'. Specify a parameter of type 'System.Char' and try again.
At line:2 char:76
+ Get-qadgroupmember $_ | Select name, samaccountname | export-csv -Delimiter <<<< ; "C:\$($_).csv"
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.
C:\g-lan infrastructure.csv
Export-Csv : Missing an argument for parameter 'Delimiter'. Specify a parameter of type 'System.Char' and try again.
At line:2 char:76
+ Get-qadgroupmember $_ | Select name, samaccountname | export-csv -Delimiter <<<< ; "C:\$($_).csv"
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.
C:\g-group.csv
put quotes around the ;
so like this
-Delimiter ";"
so like this
-Delimiter ";"
ASKER
SO I am now getting the user name but is there a way to get the Full name as well which will make it easier for my management as I really want the username and the Full name
Using "Select name, samaccountname " should give you that.
Can you try this and see what is returned
get-qaduser YOURUSERNAME | Select name, samaccountname
and if that does not work try this to give you all the default attributes to see what you want.
get-qaduser YOURUSERNAME | Select *
Can you try this and see what is returned
get-qaduser YOURUSERNAME | Select name, samaccountname
and if that does not work try this to give you all the default attributes to see what you want.
get-qaduser YOURUSERNAME | Select *
$Groups = Get-content c:\groups.txt
$Groups | Foreach {
Get-qadgroupmember $_ | export-csv "C:\$($_.)csv"
}
$Groups = Get-content c:\groups.txt
$Groups | Foreach {
Get-adgroupmember $_ | export-csv "C:\$($_.)csv"
}