New to powershell, trying to understand how things work/syntax - after scavaging microsoft docs and other postings I can't find a direct solution/proper code to get what I am looking for.
Get-Group | Select DisplayName, Members
This simply outputs two columns for me, all the groups... and all the members of each group. (300 mailboxes - and a lot of users)
When exported as CSV - the members become a string without any split/seperator outside of whitespace. This causes an issue because I am not able to sort based off member names.
the output in powershell itself would look like this for the members column:
{john doe, becky boo, bob smith...}
{ryan john, brianna nuggets, pizza pie...}
etc... goes on for the 300 mailboxes, and of course when exported itll show the full list of members.
Can someone show me how exactly I am supposed to access each individual name for each group? For example... for group1 - output EACH individual name.
output:
John Doe
Becky Boo
Bob Smith
Typically in other languages it would be something like members[0][0]would output the first ArrayList, first element... no idea how its done in powershell and can't find proper documentation for it.
Either a good direction to be pointed towards, an explanation on how to properly iterate over the object list, or store specific values... all information is helpful as I am just looking for learning material since I am doing it for fun anyway. Thanks in advance!
Edit:
Was able to output all groups & members to excel - allowing me to filter it properly with any method I choose (All members belonging to xxx group, or what groups xxx member belongs to.)
$results=@()
$groups = Get-group -resultsize unlimited | sort displayname
$groups | ForEach-Object {
$group=$_
$group.members | foreach-object {
$member = $_
$results += New-Object PSObject -property @{
Member = $member
GroupName = $group.DisplayName
MailboxType = $group.RecipientTypeDetails
GroupType = $group.GroupType
ManagedBy = $group.ManagedBy
}
}
}
$results | export-csv -path c:\All_Groups.csv