# Setup logging $baseFolder = Join-Path $env:SystemDrive "Intune" $logFile = Join-Path $baseFolder "DesktopShortcuts.log" $desktopPath = [Environment]::GetFolderPath("CommonDesktopDirectory") # Create necessary folders if (-not (Test-Path $baseFolder)) { New-Item -Path $baseFolder -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 } $rdpFiles = Get-ChildItem -Path "$desktopPath\*.rdp" -ErrorAction SilentlyContinue try { if ($rdpFiles.Count -eq 0) { Write-Log "DETECT [FAIL]: No .rdp files found on public desktop: $desktopPath" exit 1 } $allFound = $true foreach ($file in $rdpFiles) { if (-not (Test-Path (Join-Path $desktopPath $file.Name))) { Write-Log "DETECT [FAIL]: Missing: $($file.Name)" $allFound = $false } } if ($allFound) { Write-Log "DETECT [OK]: All .rdp files found on public desktop: $desktopPath" exit 0 } else { exit 1 } } catch { Write-Log "Detect error: $_" exit 1 }