Forum Discussion
SDoof
Jan 03, 2024Copper Contributor
Removing mapped SharePoint shortcuts from OneDrive automatically without end user involvement
I'm looking for a way to remove mapped SharePoint shortcuts from OneDrive for each user in my tenant without getting the end user involved.
I have found a way to disable the add OneDrive shortcut optionality in SharePoint so users can't add it moving forward:
Set-SPOTenant -DisableAddShortCutsToOneDrive $True
But that option doesn't remove the already mapped shortcuts user have in their file explorers.
The files in the SharePoint need to remain, just the users ability to access them via file explorer needs to be removed.
I'm looking for any insight, PowerShell commands, or something i have missed.
3 Replies
Sort By
- LiamJ74Copper Contributor
After seeing your post, i decided to find a working solution and create github for all sysadmin with the same problem :
https://github.com/LiamJ74/Remove-Mapped-Shortcut-Sharepoint/tree/mainthe working solution is working Manually, from Intune, and i guess from GPO too.
don't forget to launch it as user mode if you want to use it with Intune.
And directly here the powershell command for checking if user put sharepoint shortcut and delete only these if exist :
function Remove-Silent {
param(
[string]$Path
)
if (Test-Path $Path) {
Remove-Item -Path $Path -Recurse -Force -ErrorAction SilentlyContinue
}
}
$baseKey = "HKCU:\Software\SyncEngines\Providers\OneDrive"
$sousDossiers = Get-ChildItem -Path $baseKey
foreach ($sousDossier in $sousDossiers) {
$regPath = "HKCU:\Software\SyncEngines\Providers\OneDrive\$($sousDossier.PSChildName)"
$isFolderScope = Get-ItemProperty -Path $regPath -Name "IsFolderScope" -ErrorAction SilentlyContinue
if ($isFolderScope -and $isFolderScope.IsFolderScope -eq 1) {
$mountPoint = Get-ItemProperty -Path $regPath -Name "MountPoint" -ErrorAction SilentlyContinue
if ($mountPoint -and $mountPoint.MountPoint) {
$folderPath = $mountPoint.MountPoint
Write-Host "Suppression du dossier : $folderPath"
Remove-Silent -Path $folderPath
}
}
}- ElijahEdmundsCopper Contributor
Hi Liam, thank you for posting this as I'm in the same position and trying to clean Sharepoint links out of user's Onedrive before we do a tenant migration.
The script works perfectly to identify the folders I want to remove, however the remove-item command fails due to permissions issues. As near as I can tell its because the user account isn't the owner of the synced files.
Any thoughts on that? as near as I can tell there isn't a powershell command that emulates the Remove Link menu option you get when you right click
- Ash_AusCopper Contributor
SDoof you could use OneDrive sync setting. This won’t remove shortcut but will ensure files aren’t stored locally on a device.
(DehydrateSyncedTeamSites) Convert synced team site files to online-only files