I am building a script that will use the get-wmiobject cmdlet using the Win32_Product class. I am trying to do the following and getting stuck. I am trying to find for instance any Autodesk Inventor application that is installed. If it is something other than 2013 then I need to return a 0 for non compliance and if it is 2013 then I need to for it to return a 1 for compliance. I have that down without an issue. The tricky part is I also need for it to return a 1 for compliance if the application isn't installed at all. This is what I am working on and it works to the point where I can verify on a machine that has another version of the product installed or if the correct version is installed. However, if it isn't installed at this moment it will show as not compliant with this setup.
$product = "Autodesk Inventor*"
$year = "*2013*"
$adproducts=gwmi win32_product | where {$_.vendor -like "*autodesk*"}
if (($item.name -like $product) -and ($item.name -like "$year"))
{$compliance = 1}
if ($compliance -eq 1) {return $compliance}
foreach ($item in $adproducts)
{
if (($item.name -like $product) -and ($item.name -notlike "$year"))
{$compliance = 0}
}
if ($compliance -eq 0)
{return $compliance}