Working with SharePoint Online Site Groups
Summary: Use Windows PowerShell to Manage Office 365 using Windows PowerShell cmdlets, scripts, and batch processes.
Don’t worry: we didn’t forget about site groups. In fact, Windows PowerShell is a great way to manage your SharePoint site groups. The SharePoint Online Admin center has some easy-to-use methods for managing site groups, but getting to those methods can be a little cumbersome. For example, suppose you want to look at the groups, and the group members, for the site https://litwareinc.com/sites/finance. Here’s what you have to do to get that:
From the SharePoint Online Admin center, on the site collections tab, click the name of the site.
In the site collection properties dialog box, click the link that opens https://litwareinc.com/sites/finance.
On the site page, click the Settings icon (located in the upper right-hand corner of the page) and then click Site Settings:
On the Site Settings page, click Sites and permissions.
And then repeat the process for the next site you want to look at.
So is there another way to get a list of all the groups, and their users, from a given site? Well, there’s at least one other way:
$x = Get-SPOSiteGroup -Site "https://litwareinc.com/sites/finance"
foreach ($y in $x)
{
Write-Host $y.Title -ForegroundColor "Yellow"
Get-SPOSiteGroup -Site "https://litwareinc.com/sites/finance" -Group $y.Title | Select-Object -ExpandProperty Users
Write-Host
}
Admittedly, the preceding script is a tiny bit more complicated than most of the commands we’ve shown you up till now. And it is a tiny bit of a hassle as well: after all, you need to copy the code, paste into Notepad (or some other text editor), save the file using a .ps1 file extension (for example, C:\Scripts\SiteGroupsAndUsers.ps1) and then run the script from within Windows PowerShell. Although, like we said, it’s a tiny bit of a hassle; after all, running the script merely involves typing the full path to the .ps1 file:
C:\Scripts\SiteGroupsAndUsers.ps1
So yes, there’s a little bit of effort involved in all that. But look what we get back in return for that minimal amount of work:
Those are all the groups that have been created for the site https://litwareinc.com/sites/finance, as well as all the users assigned to those groups. (And, just to show off a little, we displayed the group names in yellow, to help you keep the groups, and their membership lists, separate.)
And if you think that was something, wait until you see this script:
$x = Get-SPOSite
foreach ($y in $x)
{
Write-Host $y.Url -ForegroundColor "Yellow"
$z = Get-SPOSiteGroup -Site $y.Url
foreach ($a in $z)
{
$b = Get-SPOSiteGroup -Site $y.Url -Group $a.Title
Write-Host $b.Title -ForegroundColor "Cyan"
$b | Select-Object -ExpandProperty Users
Write-Host
}
}
That script lists all the groups, and all the group memberships, for all of your SharePoint Online sites, every single one of them. Give it a try and see for yourself.
Now do you understand why you might want to use Windows PowerShell to manage SharePoint Online?
Next: A Quick Note Regarding the ForEach-Object Cmdlet