troubleshooting Question

Need help reading System.Data.DataTable

Avatar of Alice7
Alice7 asked on
7 Comments1 Solution2327 ViewsLast Modified:
Hello all, I am trying to read a datatable with powershell and I am reaching a roadblock maybe someone could help with.

Here is what I am doing.

$hostname = "host01"

$con = "server=$hostname;database=HostLog;Integrated Security=sspi"
$cmd = "select top 5  DBsizeInMB from TestLog
$da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
$dt = new-object System.Data.DataTable
$da.fill($dt) | out-null
$dt | Format-Table -autosize

My output looks like


Now my question is how would I select say the 2nd entry in DBsizeInMB? the number would be 35425.  
I would eventualy like to turn it into a variable.

I have tryed


My end goal is to create variables out of each row of data.

$item1 = $dt.tables[0]
$item2 = $dt.tables[1]
$item3 = $dt.tables[2]
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros