I tried to uninstall Microsoft Visual C++ 2022 X64 in a powershell script with this code :
$Name = "Microsoft Visual C++ 2022 X64"
$nameLikePackage = "name like '%%$Name%%'"
$uninstallCommand = "wmic product where ""$nameLikePackage"" call uninstall /nointeractive"
Write-Host "Uninstalling $Name ..."
Invoke-Expression $uninstallCommand
After execution this message appear :
instance of __PARAMETERS
{
ReturnValue = 0;
};
Of course I execute the powershell script as an administrator.
And when I check (with wmic in a cmd or in applications and funtionnalities in windows) if Microsoft Visual C++ 2022 is correctly uninstall, I see that nothing change and it's still install.
After seeing your comments I tried two methods.
The first one is with Uninstall-Package, here is the code :
Try
{
$Name = "Microsoft Visual C++ 2022 X64"
$wmiObjectToUnin = Get-WmiObject -Class Win32_Product -Filter "Name LIKE '%$Name%'"
foreach ($component in $wmiObjectToUnin)
{
$componentName = $component.Name
Write-Host "Uninstalling $componentName ..."
Uninstall-Package -Name $componentName
}
}
Catch
{
WriteHost "Package Microsoft Visual C++ X64 not install"
}
The second one is with the uninstall function of a wmi object, here is the code :
Try
{
$Name = "Microsoft Visual C++ 2022 X86"
$wmiObjectToUnin = Get-WmiObject -Class Win32_Product -Filter "Name LIKE '%$Name%'"
foreach ($component in $wmiObjectToUnin)
{
Write-Host "Uninstalling $component.Name ..."
$component.Uninstall()
}
}
Catch
{
WriteHost "Package Microsoft Visual C++ X86 not install"
}
But in both cases, nothing is uninstalled, even though the powershell window indicates that the command was executed successfully.