Powershell – Scripted check for a specific feature from an msi installer

automationmsipowershell

I need to be able to check for the installation of a particular feature from an msi installer. For context, I need to check whether the "Powershell Cmdlets" feature (TFPS from Feature table in Orca) was installed from the Team Foundation Server 2010 Power Tools installer (tfpt.msi).

I know how to check for installation of the product itself using WMI win32_product and the product code {B6DC31D8-A303-4D14-9C88-59F183F55BEC}, but the TFPS feature doesn't even install by default so it's quite common for it to be missing.

Is this possible?

Best Answer

Using the MsiQueryFeatureState should do it. You can do so from C++ or other languages. In VBScript it would be something like this (note that this is for a different MSI, please update the product GUID and feature name to suit your purpose):

dim installer, state

' Connect to Windows Installer object
set installer = CreateObject("WindowsInstaller.Installer")
state = installer.featurestate ("{4F41AD68-89F2-4262-A32C-2F70B01FCE9E}","PhotoStory")

If ( state = -2 ) then
  MsgBox "INSTALLSTATE_INVALIDARG"
 elseif (state = -1) then
  MsgBox "INSTALLSTATE_UNKNOWN"
 elseif (state = 2) then
  MsgBox "INSTALLSTATE_ABSENT"
 elseif (state = 2) then
  MsgBox "INSTALLSTATE_ADVERTISED"
 elseif (state = 3) then
  MsgBox "INSTALLSTATE_LOCAL"
 elseif (state = 4) then
  MsgBox "INSTALLSTATE_SOURCE"
End If

The interesting state is INSTALLSTATE_LOCAL. This means the feature is installed locally on the local disk.

Here is more information on the down to the wire C-style win32 call: http://msdn.microsoft.com/en-us/library/aa370361(v=vs.85).aspx