79580339

Date: 2025-04-18 02:07:34
Score: 2
Natty:
Report link

If you would like the row(s) affected and other statistics displayed as a table instead of a list, and are struggling with the fact that the statistics object is a dictionary, here is how I converted and displayed it with a little help from https://stackoverflow.com/a/18495802/2260616

Note the list of 18 statistics available at https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/provider-statistics-for-sql-server

after calling Invoke-Sqlcmd with -StatisticsVariable "sqlcmd_statistics_dictionary"

$sqlcmd_statistics_object = ($sqlcmd_statistics_dictionary `
  | %{New-Object PSObject -Property $_})
Format-Table -InputObject $sqlcmd_statistics_object -AutoSize -Property `
  IduCount, IduRows, SelectCount, SelectRows, SumResultSets, `
  Transactions, BuffersSent, BytesSent, BuffersReceived, BytesReceived
Format-Table -InputObject $sqlcmd_statistics_object -AutoSize -Property `
  ConnectionTime, ExecutionTime, NetworkServerTime, ServerRoundtrips, `
  CursorOpens, PreparedExecs, Prepares, UnpreparedExecs

The results will look like:

enter image description here

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Tom Keller