Solved

powershell

Posted on 2014-07-18
5
365 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
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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