Avatar of techdrive
techdrive
Flag for United States of America asked on

powershell select multiple fields using -expandproperty and arrange in columns exchange 2010

Good Evening I need some assistance please. I am using the following command below

get-distributiongroup -identity "groupname" | select managedby -expandproperty | select name

Now this command is great as it gives me just the name without the long path. I was trying to pull another value like the name of the group in a foreach like

This fails when trying to pull multiple fields
get-content c:\nameofdlgroups.csv | foreach { get-distributiongroup -identity $_ } | select managedby -expandproperty , displayname| select name, displayname

My end goal is to get the output to display like this below in a csv file. Its just hard displaying the name of the group plus the multiple owners of the group.

group name
groupmanagedbymember23
groupmanagedbymember13
groupmanagedbymember73
groupmanagedbymember012

group name1
groupmanagedbymember23
groupmanagedbymember13
groupmanagedbymember73
groupmanagedbymember012

group name2
groupmanagedbymember23
groupmanagedbymember13
groupmanagedbymember73
groupmanagedbymember012

group name3
groupmanagedbymember23
groupmanagedbymember13
groupmanagedbymember73
groupmanagedbymember012
PowershellActive DirectoryExchange

Avatar of undefined
Last Comment
techdrive

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Pavel Nagaev

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
techdrive

ASKER
Works great Pavel but having issues saving into a car using  export-csv
techdrive

ASKER
I think this might work and thanks also Chris Dent


$OutFile = $output = "c:\temp\gmembers.txt"
$MyList=get-content "c:\nameofdlgroups.csv" |get-distributiongroup  | select displayname -expandproperty managedby | select displayname,name

output = `
 foreach($MyItem in $MyList){

 if ($MyprevItem -ne $MyItem.DisplayName){
 $MyItem.DisplayName
 "             $($MyItem.Name)"
 $MyprevItem=$MyItem.DisplayName
 } else{
 "             $($MyItem.Name)"
 }
 }
$Output | Out-File $OutFile -Append

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck