Today I wanted to roll out Microsoft Office 2010 to a few clients but I needed to get rid of old Office installations on these systems because those could lead to problems while installing the new version. Instead of uninstalling them manually I wrote the following short PowerShell script UninstallOffice.ps1 for the task, which takes a computer name as its only parameter.
-
Param($pc = "");
-
-
if ($pc -eq "")
-
{
-
write-host ("Usage: UninstallOffice.ps1 PC") -foregroundcolor "red";
-
exit;
-
}
-
-
$programsToUninstall = @(
-
"Microsoft Office Word Viewer 2003",
-
"Microsoft Office Excel Viewer 2003",
-
"Microsoft Office PowerPoint Viewer 2003",
-
"Microsoft Office Visio Viewer 2003 (Deutsch)",
-
"Microsoft Office XP Professional",
-
"Microsoft Office Standard Edition 2003",
-
"Microsoft Office Professional Edition 2003",
-
"Microsoft Office Professional Plus 2007"
-
);
-
-
$products = get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" -ComputerName $pc;
-
if ($products.length -gt 0)
-
{
-
$products | % {
-
{
-
}
-
};
-
}
You could replace the array $programsToUninstall with a list of the programs you would like to uninstall. The following snippet gives you a list of the installed programs’ names you could use in the array.
-
get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" -ComputerName $pc | select caption
Update: If you get an error message when trying to uninstall the software, you may want to install this hotfix from Microsoft: Error message when you query Win32_Product class after you install applications by using Microsoft Windows Installer (MSI) 4.5 with “Per-User” option in Windows XP: “0×80041001 – Generic failure”.



