Classes/MsiManager.ps1

class MsiManager {
    [LibraryContext]$Context
    
    MsiManager([LibraryContext]$context) {
        $this.Context = $context
    }

    [void]Uninstall([string]$singleSoftware, [object]$softwareList) {
        if ($softwareList) {
            foreach ($softwareName in $softwareList) {
                $this.Uninstall($softwareName, $null)
            }
        }
        elseif ($singleSoftware) {
            $this.Context.LogManager.Log("Attempting to uninstall software matching: $singleSoftware")
            
            # Define the registry paths to search
            $registryPaths = @(
                "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
                "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            )
            
            # Initialize variable to store GUID
            $programGuid = $null

            # Search for the GUID in the registry paths
            foreach ($path in $registryPaths) {
                $item = Get-ItemProperty -Path "$path\*" -ErrorAction SilentlyContinue |
                        Where-Object { $_.DisplayName -like "*$singleSoftware*" }
                
                if ($item) {
                    $programGuid = $item.PSChildName
                    break
                }
            }

            # Check if the GUID was found
            if ($programGuid) {
                $this.Context.LogManager.Log("GUID found for '$singleSoftware': $programGuid")
                
                # Build the msiexec command
                $msiPath = "$env:systemroot\system32\msiexec.exe"
                $msiCommandArgs = "/X `"$programGuid`" /qn /norestart"
                
                $this.Context.LogManager.Log("Executing: $msiPath $msiCommandArgs")
                
                # Execute the command
                Start-Process $msiPath -ArgumentList $msiCommandArgs -Wait
                
                $this.Context.LogManager.Log("Uninstall of $singleSoftware OK!")
            } else {
                $this.Context.LogManager.Log("'$singleSoftware' is not installed or GUID not found.", "WARN")
            }
        }
    }
    

}