Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershell

Posted on 2014-07-18
5
Medium Priority
?
388 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 2000 total points
ID: 40204623
You probably need to expands the raw size to see the additional members..
Example
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
A hard and fast method for reducing Active Directory Administrators members.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

715 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