Solved

powershell

Posted on 2014-07-18
5
375 Views
Last Modified: 2014-07-18
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.csv'

This is the output:

Name                            Members
TEST GROUP      CN=USer Name,OU=Users,OU=test,OU=test1,OU=test2,DC=domain,DC=net,


I like the output to be like this :

Name of group                Members

Group    1                           displayname
                                             displayname
Group 2                               displayname
                                             

Please help
0
Comment
Question by:gd6627
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 40204572
Try this code and see if it works for you..
import-csv c:\PapersaveGroups.csv | Select -ExpandProperty Groupnames | foreach {Get-QADGroup $_ `
 | select name,@{Name="Members";Exp={ ($_.Members | Get-QADUser | Select -ExpandProperty DisplayName) -join "`n"}}} | Export-Csv 'c:\PWGroup CSV Files\getMembersOfgroup.csv'

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40204577
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'

Open in new window

0
 

Author Comment

by:gd6627
ID: 40204600
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 ?
0
 

Author Comment

by:gd6627
ID: 40204608
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\7b1a19ba-ab51-4ce3-9bdb-19b267711a4e.ps1:17 char:21
+    $obj | add-member <<<<  noteproperty -name "Name of Group" -$value $record.name
    + CategoryInfo          : InvalidOperation: (:) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40204623
You probably need to expands the raw size to see the additional members..
Example
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question