I am reading the book Powershell Toolmaking in a month of lunches. Which I really like!
But I am running into an issue at chapter 14, Adding database access. It seems when I am querying the database, I get next to the results, also some kind of row count.
Which is then also used as a value and is then causing an error.
When I query the database, which contains three computernames, it first displays a 3 and then the three computernames. When I pipe this into the Get-MOLSystemInfo, it is trying to connect to computer 3, before it continues with the actual machines from the database, as you can see in file1.
I have pinned it down to the Get-MOLDatabaseData function. I have paste into ISE, made some adjustments so that it works as a standalone script, and I get the same behavior. As you can see in file2.
So my question is, how do I get rid of this total count value?
Did I miss something somewhere?
I believe it's the $adapter.Fill... that returns a row count. This is how I handled it in my function:
# Fill the DataSet with the SQL Adapter info
$nRecs = $SqlAdapter.Fill($DataSet)
$nRecs | Out-Null
Basically, the .NET function is returning a row count value and you need to just pipe that output to | Out-Null to catch the output and return nothing (null). You can try just doing the | Out-Null on your fill line as well.