I think we need to close Korg down and hire Glenn. He comes up with all the answers! I never noticed that there was a delete option when editing the post. I just didn't see a delete option where one sees the reply, quote, quick reply etc. Thanks Glenn, I will remember that.

Does anyone know how I work out where in this script the loop function starts. I have tried to reset the variable to be blank after each loop but cannot get it to work. The reason being is that the script is returning the details of the anti virus, then the details of the anti spyware, but when it is supposed to return the details of the firewall it should be returning blanks for the firewall, but instead its returning the information received in the last loop from the anti spyware!

I have tried to put in an exit function so that the coding exits if say a third party firewall is not installed, but this does not work and I think its because its still finding a class called firewallproduct in WMI even if nothing is installed and using it. The working script that I have at the moment is:

 Code:
Function GetW7AVinfo(optional $machine)
dim $oSWbem,$colItems,$av[4],$colItem
 if not $machine $machine = "." endif
 
$Product = "AntiVirusProduct", "AntiSpywareProduct", "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]

;    Select $iProductState = Hex($colItem.productState, 8)
;	Case ($iProductState, 5, 2) = "00" or "01"
;	 $aReturn[5] = "Disabled"
;	 Case "10", "11"
;	 $aReturn[5] = "Enabled"
;	 EndSelect
if  $av[0] = 0 ? "Something not installed"
else
endif
EndFunction

Exit


What I am trying to get it to do go through each loop and ultimately it will send to a file anything that is not installed/updated/enabled etc. I will get to the file bit later, but I cannot work out where to dim the variable so that $ColItems is set to zero after loop. I think part of the problem is that you cannot dim an array - $product which is why its probably not working. But reading the documentation the variable is retained only within the if else endif statement therefore I assumed that the variable would only be remembered for one loop within the For each statement! Or does remembering the value of the variables only get eliminated within if else endif statements and not in for net and while .. do until statements?