I am not getting this one right. I have tried different variations, but still no joy!

My Function is as follows:

 Code:
Function GetW7AVinfo(optional $machine)
dim $oSWbem,$colItems,$av[4],$colItem
 if not $machine $machine = "." endif
 
$Product= "AntiVirusProduct"
$Product= "AntiSpywareProduct"
$Product= "FirewallProduct"

 $oSWbem = GetObject("winmgmts:\\" + $machine + "\root\SecurityCenter2")
 If @Error exit @error EndIf
 For each $SelectStatement in $Product
 $colItems = $oSWbem.ExecQuery("Select * From " + $SelectStatement)
 If @Error exit @error EndIf

 For Each $colItem In $colItems
  $av[0] = $colItem.productState
  $av[1] = $colItem.displayName
  $av[2] = $colItem.instanceGuid
  $av[3] = $colItem.pathToSignedProductExe
  $av[4] = $colItem.pathToSignedReportingExe
 Next
? $av[1]
? $av[2]
? $av[3]
? $av[4]
? $av[0]
if  $av[0] = 0 ? $Product + "not installed"
else
endif
EndFunction


If I replace $SelectStament with either AntiVirusProduct, AntiSpywareProduct and get rid of the for each $selectstatement, then code works perfectly. But I don't want to have three Functions GetW7AVinfo and Function GetW7ASinfo and Function GetW7FWinfo. In other words this works $colItems = $oSWbem.ExecQuery("Select * From AntiVirusProduct"), but I want the script to loop and replace AntiVirusProduct with AntiSpywareProduct and then FirewallProduct if that makes sense

I know that it can be done, but I cannot work out how to call AntivirusProduct, run the rest of the UDF and then return back to the top and call Antispyware Product. What the script is doing is not calling anything as its obviously not using the For each $SelectStatement in $Product.

lastly, what would be the best option to alert the administrator to a problem. My intention is to complete the coding for the script and run it as a scheduled task on each computer once every fortnight. If there is problem, the script will write to a file on the server giving out name of computer and what is not installed or up to date. But not sure whether there is a better way.