Upload af RDPSign fra arbejde-noter repo
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# ============================================================
|
||||
# CHANGELOG
|
||||
# v1.1 - Added -AllUsers switch to remove files from all user
|
||||
# desktops instead of only the public desktop.
|
||||
# Added Get-DesktopPaths helper function.
|
||||
# v1.0 - Initial version, removes from 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
|
||||
Write-Log "Running in mode: $(if ($AllUsers) { 'All Users' } else { 'Public Desktop' })"
|
||||
|
||||
foreach ($desktopPath in $desktopPaths) {
|
||||
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) from $desktopPath"
|
||||
} else {
|
||||
Write-Log "Not found, skipping: $($_.Name) on $desktopPath"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Log "Uninstall completed."
|
||||
exit 0
|
||||
} catch {
|
||||
Write-Log "An error occurred: $_"
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user