1
$GroupMembersCount = $null
$GroupMembersCount = gam print groups domain <domain> members managers owners | ConvertFrom-Csv | Where-Object { [int]$_.ManagersCount -eq 0 -and [int]$_.OwnersCount -eq 0 -and [int]$_.MembersCount -le 3 }

This gives me an object one object member is group members and that is a string with spaces like EmailAddress EmailAddress2 EmailAddress3 and so on.

One Group email can have many members.

$Results = $null
$Results = $GroupMembersCount | ForEach-Object {
   [PSCustomObject]@{
       GroupEmail = $_.Email
       members = $_.members    #THIS IS THE STING WITH 1 OR MORE MEMBERS WITH A SPACE
   }
}

I have tried to nest a foreach and the string didn't parse.

I have tried to replace the space with a comma and I have tried to convert the string both with the same error as below

$GroupMembersCount.members = $GroupMembersCount.members | ConvertFrom-String

The property 'members' cannot be found on this object. Verify that the property exists and can be set.

How do I parse that string and not lose the group email address the members belong to ?

3
  • 2
    You just want a list of individual members from the existing string? members = -split $_.members should do Commented Feb 25, 2022 at 16:35
  • I'm guessing this report is coming from Get-ADGroup + Get-ADGroupMember, if that's the case and you're looking for the output I posted in question, you should take a step back and, instead of updating the exported data, update your script generating this export. Commented Feb 25, 2022 at 16:41
  • 1
    It is coming from Google and it is telling me all the Google groups plus counts, member information and role level of each member. Your answer worked well. Commented Feb 25, 2022 at 16:46

1 Answer 1

1

Assuming it is safe to split by \s (any whitespace character), this should generate the export you're looking for:

$Results = $GroupMembersCount | ForEach-Object {
    foreach($member in $_.members -split '\s') {
        [PSCustomObject]@{
            GroupEmail = $_.Email
            Members = $member
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.