So the ExecuteReader stuff is not working. I must not be calling something I need from .Net in order to use it.
So I used the following code and can get a record retruned..I just need to know how to get the data once returned so I can output the values to Excel:
$strComputer = "targetsys01"
$SQLconn = new-object System.Data.SqlClient.SqlConnection "server=db01;database=db01;Integrated Security=sspi"
$SQLconn.Open()
$SQLcmd = new-object System.Data.SqlClient.SqlCommand
$SQLcmd.CommandTimeout = 30
$SQLcmd.CommandText = "SELECT NAME, ROOM_AREA, JACK_RACK FROM computersys WHERE NAME LIKE '" + $strComputer + "'"
write-host $SQLcmd.CommandText
$SQLcmd.Connection = $SQLconn
$SQLadapter = new-object System.Data.SqlClient.SqlDataAdapter
$SQLadapter.selectcommand = $SQLcmd
$DataSet = new-object System.Data.DataSet
$nRecs = $SqlAdapter.Fill($DataSet)
write-host ($nRecs.ToString() + " Records retrieved."
$SQLconn.Close()
if ($nRecs -gt 0)
{
write-host $DataSet.Tables[0].Rows[0]
}
This gives me 1 record returned. If I type:
PS H:\> $DataSet.Tables | Select-Object -Expand Rows
I get:
NAME ROOM_AREA JACK_RACK
---- --------- ---------
Server01 DATA CENTER 01 Row 50, Cluster 10
So what would I do to assign name, room_area, and jack_rack values to my Excel?
Something like:
$WS.Cells.Item($count, 12) = $DataSet.Tables[0].Rows[0].Columns[1].Record[0]
$WS.Cells.Item)$count, 13) = $DataSet.Tables[0].Rows[0].Columns{2].Record{0]
Thanks for the help!!