Forum Discussion
Dan_Snape
Nov 23, 2017Bronze Contributor
OneDrive external sharing and departed users
Can anyone provide some information on the best practice on dealing with OneDrive documents that have been shared externally by users who have since departed the business? We are looking at a process...
Nov 25, 2017
Use the below PowerShell PnP script to remove the already created external shares for the OneDrive. To execute this script, the user should be OneDrive for Business Administrator and to do this follow this blog.
Function Remove-OneDriveSharingLink {
param (
$OneDriveURL
)
process{
Connect-PnPOnline -Url $OneDriveURL
$Ctx= Get-PnPContext
$Files= Get-PnPListItem -List "documents"
foreach( $File in $Files)
{
$Froles= $File.RoleAssignments
$Ctx.load($Froles)
$Ctx.ExecuteQuery()
If($Froles.Count -gt 0)
{
for ($i = $Froles.Count -1; $i -ge 0 ; --$i)
{
$Link=$Froles[$i].Member
$Ctx.Load($Link)
$Ctx.ExecuteQuery()
If($Link.title -like "SharingLinks*")
{
$Froles[$i].DeleteObject()
}
$Link = $null
}
$Ctx.ExecuteQuery()
}
}
}
}
Remove-OneDriveSharingLink -OneDriveURL "https://tenantname-my.sharepoint.com/personal/alexw_tenantname_onmicrosoft_com"