Solved

powershell

Posted on 2014-07-18
5
344 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
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You probably need to expands the raw size to see the additional members..
Example
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Resolve DNS query failed errors for Exchange
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now