$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 ?
members = -split $_.membersshould doGet-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.