Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to get powershell System.Data.DataTable row count

17 October,2019 by Tom Collins

Question: i'm working with Powershell System.Data.DataTable to get values from a SQL Server to generate a report for DBAs. the report is sent via email to the DBA team. As part of the email subject - I'd like to add the row count as a summary - so the DBAs don't need to always click into the email - i.e they only need to click in if there is a row count greater than 0.

How can I get the row count from System.Data.DataTable ?

Answer: When you use the Powershell Powershell System.Data.DataTable    , certain properties are available . One those properties is the Rows.Count . This is an example of how you might use it.

Note: The Rows.Count will return an int  , so it will be necessary to cast as a string if you want to add it to the email subject line 

#create a powershell system data table

$dt = new-object "System.Data.DataTable"

#do some stuff to add rows

#get the datatable row count 

$dt.Rows.Count

#convert to a string with ToString()

$var1 = $dt.Rows.Count

$var1.ToString()

 

Read more on Powershell Datatable

How to add a row in Powershell System.Data.Datatable

Powershell insert into sql table

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to get powershell System.Data.DataTable row count


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer