I was curious if, instead of getting prompted for the local admin account for each application I want to remove, I could run PowerShell “as a different user” then use it to uninstall an application or list of applications. In this case, all of the .NET 6 stuff. Answer: absolutely.
# List all installed applications containing string "NET"
# Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like '*NET*' } | Select-Object -Property Name
# Define a static list of application names to uninstall
$appsToUninstall = @(
'Microsoft .NET Runtime - 6.0.36 (x86)',
'Microsoft .NET Host FX Resolver - 6.0.36 (x64)',
'Microsoft .NET Host - 6.0.36 (x64)',
'Microsoft .NET Host FX Resolver - 6.0.36 (x86)',
'Microsoft .NET Host - 6.0.36 (x86)',
'Microsoft .NET Runtime - 6.0.36 (x64)',
'Microsoft.NET.Workload.Emscripten.net6.Manifest (x64)'
)
# Loop through each application name in the static list
foreach ($appName in $appsToUninstall) {
# Find the application object by name
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName }
# Check if the application was found before attempting to uninstall
if ($app) {
Write-Output "Uninstalling $($app.Name)..."
$app.Uninstall() | Out-Null
Write-Output "$($app.Name) has been uninstalled successfully."
}
else {
Write-Output "Application $appName not found."
}
}