70 lines
1.9 KiB
PowerShell
70 lines
1.9 KiB
PowerShell
# ============================================================
|
|
# CHANGELOG
|
|
# v1.1 - Added -AllUsers switch to check all user desktops
|
|
# instead of only the public desktop.
|
|
# Added Get-DesktopPaths helper function.
|
|
# v1.0 - Initial version, checks public desktop only.
|
|
# ============================================================
|
|
|
|
param(
|
|
[switch]$AllUsers
|
|
)
|
|
|
|
# Setup logging
|
|
$baseFolder = Join-Path $env:SystemDrive "Intune"
|
|
$logFile = Join-Path $baseFolder "DesktopShortcuts.log"
|
|
|
|
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
|
|
}
|
|
|
|
function Get-DesktopPaths {
|
|
if ($AllUsers) {
|
|
Get-ChildItem "$env:SystemDrive\Users" -Directory | ForEach-Object {
|
|
$path = Join-Path $_.FullName "Desktop"
|
|
if (Test-Path $path) { $path }
|
|
}
|
|
} else {
|
|
[Environment]::GetFolderPath("CommonDesktopDirectory")
|
|
}
|
|
}
|
|
|
|
try {
|
|
$desktopPaths = Get-DesktopPaths
|
|
$allFound = $true
|
|
|
|
foreach ($desktopPath in $desktopPaths) {
|
|
$rdpFiles = Get-ChildItem -Path "$desktopPath\*.rdp" -ErrorAction SilentlyContinue
|
|
|
|
if ($rdpFiles.Count -eq 0) {
|
|
Write-Log "DETECT [FAIL]: No .rdp files found on desktop: $desktopPath"
|
|
$allFound = $false
|
|
continue
|
|
}
|
|
|
|
foreach ($file in $rdpFiles) {
|
|
if (-not (Test-Path (Join-Path $desktopPath $file.Name))) {
|
|
Write-Log "DETECT [FAIL]: Missing: $($file.Name) on $desktopPath"
|
|
$allFound = $false
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($allFound) {
|
|
Write-Log "DETECT [OK]: All .rdp files found on all desktop(s)"
|
|
exit 0
|
|
} else {
|
|
exit 1
|
|
}
|
|
} catch {
|
|
Write-Log "Detect error: $_"
|
|
exit 1
|
|
}
|