Forum Discussion
Removing mapped SharePoint shortcuts from OneDrive automatically without end user involvement
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/main
the 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
}
}
}
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