This topic contains 3 replies, has 3 voices, and was last updated by
June 20, 2014 at 1:16 am #16394ParticipantPoints: 0Rank: Member
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?
June 20, 2014 at 6:28 am #16400ParticipantPoints: 428Rank: Contributor
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.
June 20, 2014 at 7:37 am #16401ParticipantPoints: 0Rank: Member
Thanks man, that fixed it for me!
October 25, 2014 at 4:50 am #20056ParticipantPoints: 0Rank: Member
That fixed it for me too. The function was returning two different types of objects. First an integer and then a datarow. Don, if you see this you may want to fix the code download on morelunches?
Now I have to figure out why I can't work the the datarow objects that are coming across. Need to convert to custom objects maybe?
The topic ‘SQL example book Powershell Toolmaking’ is closed to new replies.