Prerequisites

The solution below requires only SharePoint Online Management Shell.

SharePoint Permission Groups

Each SharePoint site comes with default permission groups which can be used to assign permissions. You can see these groups on site permissions:

and the users from all the groups under https://Tenant.sharepoint.com/sites/MYSITE/_layouts/15/people.aspx?MembershipGroupId=0:

Language-dependent naming

As per Limitations of the multilingual user interface article, the permission group names are always displayed in the default site language or the language in which they were created. That means that while on English sites the default groups are called "Test's Owners" and "Test's Visitors", on a German site they will be "Besitzer von Test" and "Besucher von Test":

If you have multiple SharePoint sites and would like to assign users to appropriate permission groups, e.g. Anna the Owner to the Site Owner's Groups, regardless of the site language, you will not be able to get the appropriate group either by the name:

or by the group number as it's just the index within the collection and may vary from site to site.

Choosing group based on permissions

While it's relatively easy to navigate through UI and choose the group by its language-dependent name (assuming you know the language enough :) ), using SharePoint Online Management Shell you may want to choose groups with given permissions on all site collections regardless of their default language and the group's language-dependent name. You can do that by comparing Roles property of the SiteGroup.

Below there are several permission levels that were created with a new site:

$ViewerRoles={View Only}
$ReaderRoles={Read}
$EditorRoles={Edit}
$OwnerRoles={Full Control}

With the following cmdlet you can get the group whose role corresponds to one of the roles defined above (just replace $role with $ViewerRoles, or $EditorRoles, etc.): 

$Group= Get-SPOSiteGroup -Site $siteUrl | where {$_.Roles -eq $role}

Across multiple sites

You can also expand the cmdlet to retrieve groups from all your sites:

$sites=get-sposite
foreach($site in $sites) {Get-SPOSiteGroup -Site $site.Url | where {$_.Roles -eq {View Only}}}

The result is a bit boring since the default group with View Only access level is always called "Excel Services Viewers":

but already more interesting for Readers:

foreach($site in $sites) {Get-SPOSiteGroup -Site $site.Url | where {$_.Roles -eq {Read}}}

Full Script

 We can, of course, make it into a proper script instead of a hasty one-liner, where we not only retrieve the groups but also export them to a CSV file:

$csvPath="C:\Users\Public\ttttes.csv"
Connect-SPOService
 
$sites=Get-SPOSite
#$sites=Get-SPOSite | where {$_.Url -match "whatever"} ## Uncomment and use only if you want to select sites based on some condition
 
foreach($site in $sites)
{
    $group=(Get-SPOSiteGroup -Site $site.Url | where {$_.Roles -eq {View Only}})
    $group | Add-Member -NotePropertyName SiteUrl -NotePropertyValue $site.Url   
    $group | Export-Csv -Path $csvPath -Append 
}

Fine Print

The solution above works only with default groups and permission sets. If you assigned Full Control to your Excel Viewers Groups, it will fail.

The solution describes default SharePoint permission groups and their behaviour. If your groups are custom-created or modified, the solution might not be applicable. 

See Also