Files
RDPSign/app/Detect.ps1
T
glennigen d998c28230 feat: opdater Detect.ps1 med specifik fil-tjek og opdater README
- Implementer $expectedFiles array i Detect.ps1 for at tjekke specifikke .rdp-filnavne
- Opdater beskrivelse af Detect.ps1 i pakkens indhold tabel
- Tilføj afsnit 'Sådan opsætter du Detect.ps1' med eksempel og forklaring
- Opdater indholdsfortegnelse med nyt afsnit
2026-05-24 19:27:09 +02:00

75 lines
2.1 KiB
PowerShell

# ============================================================
# CHANGELOG
# v1.2 - Checks for specific expected .rdp filenames instead
# of just "any .rdp file exists on desktop".
# 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
)
# ============================================================
# Update this list whenever .rdp files are added or removed
# from the rdp-files\\ folder.
# ============================================================
$expectedFiles = @(
# Add your .rdp filenames here, e.g.:
# "RemoteServer1.rdp",
# "RemoteServer2.rdp"
)
# 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) {
foreach ($fileName in $expectedFiles) {
$targetFile = Join-Path $desktopPath $fileName
if (-not (Test-Path $targetFile)) {
Write-Log "DETECT [FAIL]: Missing: $fileName on $desktopPath"
$allFound = $false
}
}
}
if ($allFound) {
Write-Log "DETECT [OK]: All expected .rdp files found"
exit 0
} else {
exit 1
}
} catch {
Write-Log "Detect error: $_"
exit 1
}