0

Is it possible to get the total count of records in db (5M records) using powershell?

$database = New-Object HP.HPTRIM.SDK.Database
$database.Id = "10"
$database.WorkgroupServerName = "dbnonprod"
$database.Connect() 
$recordSearch = New-Object HP.HPTRIM.SDK.TrimMainObjectSearch($database, [HP.HPTRIM.SDK.BaseObjectTypes]::Record)
$recordSearch.SetsearchString("All")

$a = 0

foreach ($record in $recordSearch) {
$a+= $record.count
}
echo $a 

And this is my error when trying to get the totalcount store on the db from content manager database

Content Manager Workgroup Server on 'dbnonprod' reported an error. Could not serialize the server-side recordset. Error with SQL Connection: The ODBC connection is not active any more, could be forcibly closed by the server or in load balancing.

siennac
  • 37
  • 5
  • 1
    I don't have a HPTrim to test with, but look at [search](https://content-manager-sdk.github.io/Community/91/programming_guide.html#Searching_for_HPE_Records_Manager_objects) and its [count](https://content-manager-sdk.github.io/Community/91/class_h_p_1_1_h_p_t_r_i_m_1_1_s_d_k_1_1_trim_main_object_search.html#a2f478a8c30d8c57f8c22388be5b963ab) method, which should return you the object count instead of iterating the result set. – vonPryz Jun 08 '22 at 06:44
  • The SDK and PowerShell have different code. – siennac Jun 08 '22 at 07:08
  • Yes, because the SDK samples are C#. Conversion to Powershell is usually [quite simple](https://stackoverflow.com/a/2143945/503046), and if that fails, one can embed C# into PS code too. – vonPryz Jun 08 '22 at 07:49
  • How should I integrate this code? HP.HPTRIM.SDK.TrimMainObjectSearch.FastCount. To prevent the connection from being disconnected. – siennac Jun 22 '22 at 07:01

0 Answers0