# Setup logging $baseFolder = Join-Path $env:SystemDrive "Intune" $logFile = Join-Path $baseFolder "DesktopShortcuts.log" $desktopPath = [Environment]::GetFolderPath("CommonDesktopDirectory") # Create necessary folders $folders = @( $baseFolder ) foreach ($folder in $folders) { if (-not (Test-Path $folder)) { New-Item -Path $folder -ItemType Directory -Force | Out-Null } } function Write-Log { param($Message) $logMessage = "$(Get-Date -Format 'dd-MM-yyyy HH:mm'): $Message" Add-Content -Path $logFile -Value $logMessage Write-Host $logMessage } try { Get-ChildItem -Path ".\rdp-files\*.rdp" | ForEach-Object { $targetFile = Join-Path $desktopPath $_.Name if (Test-Path $targetFile) { Remove-Item -Path $targetFile -Force Write-Log "Removed: $($_.Name)" } else { Write-Log "Not found, skipping: $($_.Name)" } } Write-Log "Uninstall completed from public desktop: $desktopPath" exit 0 } catch { Write-Log "An error occurred: $_" exit 1 }