Attention au côté juridique de cette opération.
Dans certain cas de figure nous sommes amenés à devoir faire une liste de tout accès externe à différents types de ressources, dans le cas présent nous allons lister l'ensemble des OneDrives avec un partage externe, pour ce faire vous aurez besoin de :
- Powershell 5.1,
- Le module Sharepoint Online,
- un accès Sharepoint Admin.
Vous pouvez maintenant lancer le script en prenant soin de modifier les url de connexion (L2 et L59)
# Connection to Sharepoint Online
Connect-SPOService -Url https://contoso-admin.sharepoint.com # (Please change the connection URL)
# Get the list of All OneDrives
$AllOneDrive = Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'"
# Define variables
$ArrayOneDriveMembers = @()
$SortOneDrive = $AllOneDrive | sort Url
$X = 0
$SortOneDrive | foreach {
$OneDriveUrl = $_.Url
$OneDriveOwner = $_.Owner
$OneDriveStorageQuota = $_."Storage Quota"
$OneDriveTitle = $_.Title
# Get Member of current OneDrive
Try {
$OneDriveMembers = Get-SPOUser -Site $OneDriveUrl -ErrorAction stop
}
Catch {
Write-Warning $($_)
Write-Output "$OneDriveUrl;$OneDriveTitle" | Add-Content C:\temp\Onedriveerrors.txt
}
# Get External members
$OneDriveExternal = $OneDriveMembers.where({$_.Usertype -eq "Guest"})
If ($OneDriveExternal.count -ne 0) {
Write-Host "External Users are present in $OneDriveTitle" -ForegroundColor Green
$OneDriveExternal.count
$OneDriveExternal | foreach {
$DisplayName = $_.DisplayName
$LoginName = $_.LoginName
# Store Data
$ArrayOneDriveMembers += New-Object psobject -Property @{
OneDriveUrl = $OneDriveUrl
OneDriveOwner = $OneDriveOwner
OneDriveStorageQuota = $OneDriveStorageQuota
OneDriveTitle = $OneDriveTitle
DisplayName = $DisplayName
LoginName = $LoginName
}
# Release
$DisplayName = $null
$LoginName = $null
}
}
# Release
$OneDriveUrl = $null
$OneDriveOwner = $null
$OneDriveStorageQuota = $null
$OneDriveTitle = $null
$OneDriveMembers = $null
# After 500 connection, reconnect to Sharepoint
If ($x -eq 500) {
# Connect to Sharepoint
Connect-SPOService -Url https://contoso-admin.sharepoint.com
$x =0
}
$x++
}
# Export Data
$ArrayOneDriveMembers | Export-Csv c:\temp\ExternalOneDriveMembers.csv -Encoding UTF8 -Delimiter ";" -NoTypeInformation