OK, I found another code that is faster and works.
try{
$objConn = New-Object System.Data.OleDb.OleDbConnection("Provider=Search.CollatorDSO;Extended Properties='Application=Windows'")
$sqlCommand = New-Object System.Data.OleDb.OleDbCommand("GROUP ON workid [0] AGGREGATE COUNT() as 'Total' OVER (SELECT workid FROM systemindex)")
$sqlCommand.Connection = $objConn
$objConn.open()
$reader = $sqlCommand.ExecuteReader()
try{
$ignore = $reader.Read() #will cause an error but we can ignore it... without this we won't have data
} catch {}
$value = $reader[2]
$value = "{0:N0}" -f $value
} catch {}
So my problem is solved