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
}
}
}