Tuesday, June 16, 2015

Group membership in SharePoint Online

Yesterday, one of my customers asked me to provide her a list of groups and its members for her main SharePoint site. An internal technician used to provide her that information every month by manually going to the site and copying/pasting screenshots of each group.
I decided to use PowerShell for that. I have never used PS cmdlets for SharePoint Online before, so this is my first try. I hope it is useful for you.

$cred = Get-Credential
$adminSite = "https://contoso-admin.sharepoint.com/"
$rootSite =  "https://contoso.sharepoint.com/"
Connect-SPOService -Url $adminSite -Credential $cred

$groups = Get-SPOSiteGroup -Site $rootSite

$objectCollection = $groups |

    ForEach-Object {
        $groupName = $_.LoginName
        $_.Users | ForEach-Object {
            $user = Get-SPOUser -Site $rootSite -LoginName $_
            $properties = @{
                GroupName = $groupName;
                UserName = $user.DisplayName;
                LoginName = $_
            New-Object -TypeName PSObject -Property $properties



Let me know in the comments if there is something that can be done to make it run faster (it takes about 80 second to complete for this specific tenant).

No comments:

Post a Comment