gd6627
asked on
powershell
I have this script am working with to extract memebers of a group. The script works but I like to modify it to be more user friendly
This is the script:
import-csv c:\PapersaveGroups.csv | Select -ExpandProperty Groupnames | foreach {Get-QADGroup $_ `
| select name, @{Name="Members";Exp={ $_.Members -join ", "}}} | Export-Csv 'c:\PWGroup CSV Files\getMembersOfgroup.cs v'
This is the output:
Name Members
TEST GROUP CN=USer Name,OU=Users,OU=test,OU=t est1,OU=te st2,DC=dom ain,DC=net ,
I like the output to be like this :
Name of group Members
Group 1 displayname
displayname
Group 2 displayname
Please help
This is the script:
import-csv c:\PapersaveGroups.csv | Select -ExpandProperty Groupnames | foreach {Get-QADGroup $_ `
| select name, @{Name="Members";Exp={ $_.Members -join ", "}}} | Export-Csv 'c:\PWGroup CSV Files\getMembersOfgroup.cs
This is the output:
Name Members
TEST GROUP CN=USer Name,OU=Users,OU=test,OU=t
I like the output to be like this :
Name of group Members
Group 1 displayname
displayname
Group 2 displayname
Please help
Try this:
$groups = import-csv c:\PapersaveGroups.csv | Select -ExpandProperty Groupnames
foreach {$group in $groups) {
$obj = new-object psobject
$record = get-qadgroup
$obj | add-member noteproperty -name "Name of Group" -$value $record.name
$x=0
foreach ($mbr in $record.members) {
$x++
$obj | add-member noteproperty -name "Group$x" -value $mbr.displayname
}
$records += $obj
}
$records | Export-Csv 'c:\PWGroup CSV Files\getMembersOfgroup.csv'
ASKER
subsun: thanks for the reply . I tried the script you submitted but it resulted on the output of one member only when I ran it . the group had 4 members ?
ASKER
Sirbounty:
I get the below error when trying to run your code
Add-Member : The SecondValue parameter is not necessary for a member of type "NoteProperty" and should no
t be specified. Do not specify the SecondValue parameter when adding members of this type.
At C:\AppData\Local\Temp\7b1a 19ba-ab51- 4ce3-9bdb- 19b267711a 4e.ps1:17 char:21
+ $obj | add-member <<<< noteproperty -name "Name of Group" -$value $record.name
+ CategoryInfo : InvalidOperation: (:) [Add-Member], InvalidOperationException
+ FullyQualifiedErrorId : Value2ShouldNotBeSpecified ,Microsoft .PowerShel l.Commands .AddMember Command
I get the below error when trying to run your code
Add-Member : The SecondValue parameter is not necessary for a member of type "NoteProperty" and should no
t be specified. Do not specify the SecondValue parameter when adding members of this type.
At C:\AppData\Local\Temp\7b1a
+ $obj | add-member <<<< noteproperty -name "Name of Group" -$value $record.name
+ CategoryInfo : InvalidOperation: (:) [Add-Member], InvalidOperationException
+ FullyQualifiedErrorId : Value2ShouldNotBeSpecified
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window