/build/static/layout/Breadcrumb_cap_w.png

How to create a PowerShell Script to detect all versions of Microsoft Project present on machine and Uninstall all except the latest version?

Hello Friends,

I am assigned this project to Clean machines having multiple versions of Project installed with single and latest version out of them. According to reports generated their are 5 versions of Microsoft Project present in our organization namely 

Microsoft Project 2003

Microsoft Project 2007

Microsoft Project 2010

Microsoft Project 2013

Microsoft Project 2016

These versions further are classified into "Project Standard" and"Project Professional" and further into 32bit/64bit installation 

The task is to detect which out of these versions are installed on machine then Uninstall  all except the latest one out of them. I have tried to put some logic like below but it won't work because scenarios are way more to consider. I really appreciate if someone can guide me through the solution.


if( Present Project2007 and Project2010..... and ProjectN)

{

Uninstall(All except ProjectN)

}

if( Present Project2007 and Project2010..... and Project(N - 1))

{

Uninstall(All except Project(N - 1))

} and so on 

but if a machine has Project2007 and Project 2013 installed then this logic will fail


Here is my incomplete code appreciate if some one can help!

 $Project2003STD = Test-Path "C:\Program Files\Office 2003\OFFICE11\WINPROJ.EXE"

        $Project2003x86STD = Test-Path "C:\Program Files (x86)\Office 2003\OFFICE11\WINPROJ.EXE"


        $Project2003Pro = Test-Path "C:\Program Files\Microsoft Office\OFFICE11\WINPROJ.EXE"

        $Project2003x86Pro = Test-Path "C:\Program Files (x86)\Microsoft Office\OFFICE11\WINPROJ.EXE"


        $Project2007STD = Test-Path "C:\Program Files\Office 2007\Office12\WINPROJ.EXE"

        $Project2007x86STD = Test-Path "C:\Program Files (x86)\Office 2007\Office12\WINPROJ.EXE"


        $Project2007Pro = Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\PRJPRO\PrjProWW.XML"

        $Project2007x86Pro = Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\PRJPRO\PrjProWW.XML"


        $Project2010STD = Test-Path "C:\Program Files\Office 2010\Office14\WINPROJ.EXE"

        $Project2010x86STD = Test-Path "C:\Program Files (x86)\Office 2010\Office14\WINPROJ.EXE"


        $Project2010STD64bit = Test-Path "C:\Program Files\Microsoft Office\Office14\WINPROJ.EXE"


        $Project2010Pro = Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\PRJPRO\PrjProWW.XML"

        $Project2010x86Pro = Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\PRJPRO\PrjProWW.XML"


        $Project2013STD = Test-Path "C:\Program Files\Microsoft Office\Office15\WINPROJ.EXE"

        $Project2013STDx86 = Test-Path "C:\Program Files (x86)\Microsoft Office\Office15\WINPROJ.EXE"


        $ProJect2016Pro = Test-Path "C:\Program Files\Microsoft Office\root\Office16\WINPROJ.EXE"

        $Project2016Prox86 = Test-Path "C:\Program Files (x86)\Microsoft Office\root\Office16\WINPROJ.EXE"


        

        if($is64bit)

       { 

       

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD) -and ($Project2007Pro -or $Project2007x86Pro) -and ($Project2010STD -or $Project2010x86STD)  -and ($Project2010STD64bit) -and ($Project2010Pro -or $Project2010x86Pro) -and ($Project2013STDx86 -or $Project2013STD) -and ($ProJect2016Pro -or $ProJect2016Prox86))

        {

        

        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

        #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }


        #Project2007x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }

        #Project2010STD64bit/#Project2010STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2010Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2010x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2013STDx86

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2013STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        

        

        }

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD) -and ($Project2007Pro -or $Project2007x86Pro) -and ($Project2010STD -or $Project2010x86STD)  -and ($Project2010STD64bit) -and ($Project2010Pro -or $Project2010x86Pro) -and ($Project2013STDx86 -or $Project2013STD))

        {

        #Project2010x86Pro

       

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

        #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }


        #Project2007x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }

        #Project2010STD64bit/#Project2010STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2010Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2010x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        }

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD) -and ($Project2007Pro -or $Project2007x86Pro) -and ($Project2010STD -or $Project2010x86STD)  -and ($Project2010STD64bit) -and ($Project2010Pro -or $Project2010x86Pro))

        {

        



        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

        #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }


        #Project2007x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }

        #Project2010STD64bit/#Project2010STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


       

        }

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD) -and ($Project2007Pro -or $Project2007x86Pro) -and ($Project2010STD -or $Project2010x86STD)  -and ($Project2010STD64bit))

        {

        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

        #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }


        #Project2007x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }

        #Project2010STD64bit/#Project2010STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010x86Pro

       

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        }

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD) -and ($Project2007Pro -or $Project2007x86Pro) -and ($Project2010x86STD))

        {

        

        #Project2010x86Pro

       

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

        #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }


        #Project2007x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }

       }

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD) -and ($Project2007Pro -or $Project2007x86Pro))

        {

        

        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

         #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

       }

        if(($Project2003STD -or $Project2003x86STD) -and ($Project2003Pro -or $Project2003x86Pro) -and ($Project2007STD -or $Project2007x86STD))

        {

       #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

       }



       if(($Project2003STD -or $Project2003x86STD) -and ($Project2010STD -or $Project2010x86STD)  -and ($Project2010STD64bit) -and ($Project2010Pro -or $Project2010x86Pro) -and ($Project2013STDx86 -or $Project2013STD) -and ($ProJect2016Pro -or $ProJect2016Prox86))

        {

        

        #Project2003STD

        if ($Project2003STD -or $Project2003x86STD)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }


        #Project2003Pro

        if ($Project2003Pro -or $Project2003x86Pro)

        {

        Execute-Msi -Action 'Uninstall' -Path '{903A0409-6000-11D3-8CFE-0150048383C9}' -Parameters "/qn"

        }

        #Project2007STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2007Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }


        #Project2007x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true 

        }

        #Project2010STD64bit/#Project2010STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2010x86STD

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2010Pro

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        #Project2010x86Pro

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjPro /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2013STDx86

        if (Test-Path "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Office Setup Controller"

        execute-process "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }

        #Project2013STD

        if (Test-Path "C:\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller\SETUP.EXE")

        {

        Copy-Item -Recurse "$dirFiles\UninstallProject.xml" "C:\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller"

        execute-process "C:\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller\setup.exe" -Parameters '/uninstall PrjStd /dll OSETUP.DLL /config UninstallProject.xml' -ContinueOnError $true  

        }


        

        

        }



        }




0 Comments   [ + ] Show comments

Answers (2)

Posted by: SMal.tmcc 5 years ago
Red Belt
0

have you tried testing using WMIC?


wmic product where "Name like 'Microsoft Project%%' and NOT version LIKE '16.%%'" call uninstall /nointeractive

or

wmic product where "Name like 'Microsoft Project%%' and NOT Name LIKE '%%2016'" call uninstall /nointeractive


Comments:
  • Hi SMal.tmcc , Thanks for the comment. I have tried this but it was not working for Microsoft Project. I belive wmic will not uninstall Office Products.
    :(

    https://social.technet.microsoft.com/Forums/en-US/de092763-b159-43c4-aead-8869a97994c9/uninstall-office-2013-via-wmic?forum=w7itproui - Aman12341122 5 years ago
    • will all the old versions be upgraded to 2016 or are trying to remove project all together? - SMal.tmcc 5 years ago
      • Older version will not be upgraded we need to uninstall them.... I have detection logic, I have Uninstall String for each cases I need something through which this can be done without writing 1000s line of codes. - Aman12341122 5 years ago
      • what are you going to use to deploy your script with? - SMal.tmcc 5 years ago
Posted by: rad33k 5 years ago
Fourth Degree Brown Belt
0

Hi,
I'm more a VBS guy and I like the multidimensional arrays for such cases :) ... so I would use an array with all the data and then employ a for/for-each loop.
My first thought is to use the following logic - check what is currently installed in the descending order (starting from Prj 2013 to 2003 - project 2016 should be checked out of the loop as this one is currently the latest available and will never be removed).
The first app detected in a loop is the latest one on a machine. All next apps detected have to be removed. If only one version is detected then there is nothing to do by the script.

Additionally, do you really need to copy "UninstallProject.XML" to the "Office Setup Controller" folder?
According to the MS docs (I checked 2013 only) you can specify a fully qualified path to the custom config file.

Here is a draft of the code just to show you the logic - you would need to add the missing products and fix all the typos, quotes and any other issues :)

<#
An array contains following elements. You would need to fill it out with the remaining items (in the descending order - I put there only few of them for reference).

$ArrProducts[$i][0] - App Name
$ArrProducts[$i][1] - Main executable path
$ArrProducts[$i][2] - App release (pro or std) used as Uninstall param // or MSI for 2003 version.
$ArrProducts[$i][3] - App architectire a.k.a. bitness // or MSI GUID for 2003
$ArrProducts[$i][4] - App version folder name
#>
$ArrProducts = @()
$ArrProductsToRemove = @()
$ArrIndex = @()

#Project 2016 moved out of the array
$ArrProducts = ("Project2013STD", "C:\Program Files\Microsoft Office\Office15\WINPROJ.EXE","PrjStd","x64","OFFICE15" ),
("Project2010Pro","C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\PRJPRO\PrjProWW.XML","PrjPro","x64","OFFICE14"),
("Project2007STD","C:\Program Files\Office 2007\Office12\WINPROJ.EXE","PrjStd","x64","OFFICE12"),
("Project2003x86STD","C:\Program Files (x86)\Office 2003\OFFICE11\WINPROJ.EXE","MSI","{903A0409-6000-11D3-8CFE-0150048383C9}")

#It's always recomended to log the operations performed by the script
$LogPath = $Env:windir +"\Logs\MS_Project_Cleanup_Script_1_0_0.log"
$LatestVer = "none"
$iDetectedApps = 0

"-" * 70 # | Out-File $LogPath -Append
"$(Date)`t Script started" # | Out-File $LogPath -Append

$Project2016Pro = Test-Path "C:\Program Files\Microsoft Office\root\Office16\WINPROJ.EXE"
$Project2016Prox86 = Test-Path "C:\Program Files (x86)\Microsoft Office\root\Office16\WINPROJ.EXE"
If ($Project2016Pro)
{
$LatestVer = "Project2016Pro"
"$(Date)`t Latest version detected - Project2016Pro" # | Out-File $LogPath -Append
}
ElseIf ($Project2016Prox86)
{
$LatestVer = "Project2016Prox86"
"$(Date)`t Latest version detected - Project2016Prox86" # | Out-File $LogPath -Append
}

For ($i=0;$i -lt $ArrProducts.Length;$i++)
{
If (Test-Path $ArrProducts[$i][1])
{
If ($LatestVer -eq "none")
{
#Set the latest version, the one which won't be removed (it is the newest one on a machine)
$LatestVer = $ArrProducts[$i][0]
"$(Date)`t Latest version detected - " +$ArrProducts[$i][0] # | Out-File $LogPath -Append
}
Else
{
#Older version detected - add its index to a new array (or you can modify the script to execute a removal here...)
"$(Date)`t Older version detected: '" +$ArrProducts[$i][0] +"'" # | Out-File $LogPath -Append
$ArrProductsToRemove+=$i
}
}
}

If ($ArrProductsToRemove.Length -le 0)
{
#Nothing to remove
Exit 0
}
Else
{
#Uninstall
ForEach ($arrIndex in $ArrProductsToRemove)
{
If ($ArrProducts[$ArrIndex][2] -eq "MSI")
{
#Office 2003 detected - MSI removal procedure
Execute-Msi -Action 'Uninstall' -Path $ArrProducts[$ArrIndex][3] -Parameters "/qn"
}
Else{
If ($ArrProducts[$ArrIndex][3] -eq "x86")
{
$strPFiles = ${Env:ProgramFiles(x86)}
}
Else{
$strPFiles = $Env:ProgramW6432
}
$strEXEPath = $strPFiles +"\Common Files\microsoft shared\" +$ArrProducts[$ArrIndex][4] +"\Office Setup Controller\setup.exe"
$Parameters = "/uninstall $($ArrProducts[$ArrIndex][2]) /dll OSETUP.DLL /config `"$PSScriptRoot\UninstallProject.xml`""
execute-process $strEXEPath -Parameters $Parameters -ContinueOnError $true
}
}
}

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ