Hello everyone! How are you?
I created a PowerShell script (for a Fixlet) to remove .NET in some versions (EOL 7 and 5).
Here is the relevance:
exists key whose(value "DisplayName" of it as string starts with "Microsoft .NET 7.0") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries) OR exists keys whose(value "DisplayName" of it as string starts with "Microsoft ASP.NET Core 7.0") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries) OR exists keys whose(value "DisplayName" of it as string starts with "Microsoft .NET Runtime - 7.0") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries) OR exists keys whose(value "DisplayName" of it as string starts with "Microsoft .NET 5.0") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries) OR exists keys whose(value "DisplayName" of it as string starts with "Microsoft ASP.NET Core 5.0") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries) OR exists keys whose(value "DisplayName" of it as string starts with "Microsoft .NET Runtime - 5.0") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries)
Here is the script:
function UninstallProgram {
param(
[string]$programName
)
$registryKeys = @(
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
)
$programsFound = $true
while ($programsFound) {
$programsFound = $false
foreach ($registryKey in $registryKeys) {
$uninstallKeys = Get-ChildItem $registryKey | Get-ItemProperty
foreach ($key in $uninstallKeys) {
if ($key.DisplayName -match $programName) {
$uninstallString = $key.UninstallString
# Add space before the silent uninstall parameters
if ($uninstallString -notmatch "(/quiet|/qn|/silent|/s)") {
$uninstallString += " /quiet /norestart /qn"
}
# Correct command if necessary
if ($uninstallString -match "msiexec") {
$uninstallString = $uninstallString.Replace("/I{", "/X{")
}
Write-Host "UninstallString value: $uninstallString"
Write-Host "Uninstalling $($key.DisplayName) silently..."
Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString" -WindowStyle Hidden -Wait
Write-Host "$($key.DisplayName) uninstalled successfully."
# Set flag to true to check for more instances
$programsFound = $true
}
}
}
}
if (-not $programsFound) {
Write-Host "$programName not found. No action taken."
}
}
UninstallProgram "Microsoft .NET 7.0"
UninstallProgram "Microsoft ASP.NET Core 7.0"
UninstallProgram "Microsoft .NET Runtime - 7.0"
UninstallProgram "Microsoft .NET 5.0"
UninstallProgram "Microsoft ASP.NET Core 5.0"
UninstallProgram "Microsoft .NET Runtime - 5.0"
I conducted various tests in different scenarios using the script and relevance, utilizing both the Fixlet Debugger and deploying through BigFix. The tests were performed on my computer and a colleague’s computer. All tests were successful, and all versions of .NET (EOL) were properly removed.
However, when performing the tests on a different server and in a different environment with Windows 11 and BigFix Agent version 10.0.46, the fixlet remained in a running status without any progress on all the machines tested.
Could the issue be related to permissions, interference from firewall or security software?
I appreciate the help in advance, guys!