OneDrive external sharing and departed users

Steel Contributor

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 to disable the sharing, but I can't find how to do this easily.

Thanks

4 Replies
Do you want to keep those files shared with the external users, or remove that?
If the latter then simply move the files to another location and the sharing will stop.

We are looking to remove the sharing. Thanks for the idea, that seems a good one if there is nothing more formal. 

You can try disabling the sharing on the site via powershell, I'm not sure what happens to existing links, but one would think it would disable them as well but it may just disable links going forward. Something you could try out.

Connect-SPOService
set-sposite -identity "URL to OneDrive site" -SharingCapability Disabled


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"