Forum Discussion
Jonathan Nunez
Nov 18, 2019Brass Contributor
Creating script to export reports on users and their OneDrive for external sharing
Greetings, I was wondering if anyone has an idea of how to make a script that allows me to see who are the members in an Azure AD Security Group and see if they have External Sharing Capabilities...
- Nov 19, 2019
Try the below script :
Connect-AzureAD Connect-SPOService -url https://domain-admin.sharepoint.com $Result = @() $GroupName = "YourSecurityGroup" $GroupObj = Get-AzureADGroup -SearchString $GroupName $GroupMembers = Get-AzureADGroupMember -ObjectId $GroupObj.ObjectId | Select DisplayName, UserPrincipalName $OneDriveSites = Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'" | Select Owner, Url, SharingCapability ForEach ($User in $GroupMembers) { $Site = ($OneDriveSites | Where-Object { $_.Owner -eq $User.UserPrincipalName }) $Result += New-Object PSObject -property @{ UserName = $User.DisplayName UserPrincipalName = $User.UserPrincipalName SharingCapability = if ($Site -ne $null) { $Site.SharingCapability } else { $null } URL = if ($Site -ne $null) { $Site.Url } else { $null } } } $Result | Select UserName, SharingCapability, URL
VasilMichev
Nov 19, 2019MVP
Simply get the list of members of the group and then run the Get-SpoSite cmdlet for each member by adjusting the filter. Here's how to do it for a given user:
Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Owner -eq 'vasil@michev.info' -and Url -like '-my.sharepoint.com/personal/'" | select Owner, Url, SharingCapability