I'd like to do this using the win32_product wmi class.
I need the script to simply count the number of products installed and also output the time taken to execute the script.
What I have atm doesn't seem to work correctly:
    $count = 0
    $products = get-wmiobject -class "Win32_Product"
    foreach ($product in $products) {
          if ($product.InstallState -eq 5) {
                count++
          }
    }
    write-host count