# Define a function for logging to C:\temp function Log-Message { param ( [string]$message ) $logFile = "C:\temp\DellSupportAssistUninstall.log" $logDir = Split-Path -Path $logFile -Parent # Create the log directory if it doesn't exist if (-not (Test-Path -Path $logDir)) { New-Item -Path $logDir -ItemType Directory -Force } $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" Add-Content -Path $logFile -Value "$timestamp - $message" } # Define a function to get installed Dell SupportAssist products function Get-DellSupportAssist { $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall" $products = Get-ChildItem $registryPath | Get-ItemProperty | Where-Object { $_.DisplayName -match "Dell SupportAssist" -and $_.Displayname -notmatch "Dell SupportAssist OS Recovery Plugin for Dell Update" } return $products } # Define a function to check if a version is less than 5 # Get installed products $DellSupportAssist = Get-DellSupportAssist # List products found Log-Message "Products found:" foreach ($product in $DellSupportAssist) { Write-log "$($product.DisplayName) version $($product.DisplayVersion)" Log-Message "$($product.DisplayName) version $($product.DisplayVersion)" } # Uninstall products with version less than 5 Log-Message "Uninstalling products with version less than 5:" foreach ($product in $DellSupportAssist) { Log-Message "Uninstalling $($product.DisplayName) version $($product.DisplayVersion)" $uninstallString = $product.UninstallString if ($uninstallString) { Log-Message "Uninstall command: $uninstallString" Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString /qn /quiet /norestart" -Wait } else { Log-Message "No uninstall string found for $($product.DisplayName)" } } # Get products after uninstallation $DellSupportAssistAfter = Get-DellSupportAssist # List products remaining after uninstallation Log-Message "Products remaining after uninstallation:" foreach ($product in $DellSupportAssistAfter) { Log-Message "$($product.DisplayName) version $($product.DisplayVersion)" } # After checking remaining products if ($DellSupportAssistAfter.Count -eq 0) { # No products found (removal successful) If (!(Test-Path "C:\ProgramData\KBR")) { New-Item -Path "C:\ProgramData\KBR" -ItemType Directory -Force } New-Item -Path "C:\ProgramData\KBR\DellSupportAssist_uninstall_1.0" -ItemType File -Force } else { Log-Message "Products found (removal failed)" Exit 0 }