Classes/Win32ProductManager.ps1

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

    [void]Uninstall([string]$singleSoftware, [object]$softwareList) {
        if ($softwareList) {
            foreach ($softwareName in $softwareList) {
                $this.Uninstall($softwareName, $null)
            }
        }
        elseif($singleSoftware) {
            $installed = Get-Package | Where-Object { $_.Name -ieq $singleSoftware }

            if ($installed.Count -eq 0) {
                $this.Context.LogManager.Log("No installed Win32Product(s) matching $singleSoftware were found", "WARN")
            } elseif ($installed.Count -ge 10) {
                $this.Context.LogManager.Log("Found $($installed.Count) Win32Product(s) matching $singleSoftware => This is too much, skipping!", "ERROR")
            } else {
                foreach ($m in $installed) {
                    $this.Context.LogManager.Log("Attempting to uninstall Win32Product: $($m.Name)")
                    Uninstall-Package $m.Name -ForceBootstrap -Force -Confirm:$false -ErrorAction SilentlyContinue
                }

                #check for uninstall
                $remaining = Get-Package | Where-Object { $_.Name -ieq $singleSoftware }
                if ($remaining.Count -eq 0) {
                    $this.Context.LogManager.Log("All Win32Product(s) matching $singleSoftware were uninstalled!")
                } else {
                    $this.Context.LogManager.Log("Not all Win32Product(s) matching $singleSoftware were uninstalled! Maybe they need more time to uninstall but currently they are still there", "ERROR")
                }
            }
        }
    }
}