Untitled

 avatar
unknown
powershell
a year ago
1.9 kB
17
Indexable
<#
.SYNOPSIS
    This script uninstalls any applications with "Dell" in the name using the uninstall string from the registry.
    
.DESCRIPTION
    This script searches the registry for uninstall strings of applications that have "Dell" in their name, 
    and then executes the command to uninstall them.

.AUTHOR
    Jack Harvard, ComputerWorld
#>

# Log file path
$logPath = "C:\DellUninstallLog.txt"

# Function to log to a file
function LogToFile {
    param([string]$message)
    Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): $message"
}

# Ensure the script is run with admin privileges
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File $($MyInvocation.MyCommand)" -Verb RunAs
    exit
}

# Search the registry for uninstall strings of applications with "Dell" in the name
$apps = Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
        Get-ItemProperty |
        Where-Object { $_.DisplayName -like "*Dell*" } |
        Select-Object -Property DisplayName, UninstallString

# Uninstall each application found
foreach ($app in $apps) {
    LogToFile "Attempting to uninstall: $($app.DisplayName)"
    try {
        $uninstallString = $app.UninstallString -replace 'msiexec.exe', 'msiexec' -replace '/I', '/X'
        Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString /qn /norestart" -Wait -PassThru
        LogToFile "Successfully uninstalled: $($app.DisplayName)"
    } catch {
        LogToFile "Failed to uninstall: $($app.DisplayName). Error: $_"
    }
}

LogToFile "Uninstallation process completed."
Editor is loading...
Leave a Comment