# Create SqlConnection object and define connection string $con = New-Object System.Data.SqlClient.SqlConnection $con.ConnectionString = "Data Source=NickMini\sqlexpress;Integrated Security=true;Initial Catalog=NickTest" $con.open() # Create SqlCommand object, define command text, and set the connection $cmd = New-Object System.Data.SqlClient.SqlCommand $cmd.CommandText = "SELECT * FROM employee" $cmd.Connection = $con # Create SqlDataReader $dr = $cmd.ExecuteReader() Write-Host If ($dr.HasRows) { for ($i=0; $i -lt $dr.fieldCount; $i ++) { $name=$dr.getname($i); Write-host "$name`t" -nonewline } write-host While ($dr.Read()) { for($i=0; $i -lt $dr.fieldCount; $i++) { $value=$dr.getvalue($i); Write-Host "$value`t" -nonewline } write-host } } else { Write-Host The DataReader contains no rows. } Write-Host # Close the data reader and the connection $dr.Close() $con.Close()