SQL example book Powershell Toolmaking

Welcome Forums General PowerShell Q&A SQL example book Powershell Toolmaking

This topic contains 3 replies, has 3 voices, and was last updated by

4 years, 2 months ago.

  • Author
  • #16394

    Points: 0
    Rank: 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?


    Ramon Bruin

  • #16400

    Points: 428
    Helping Hand
    Rank: 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.

  • #16401

    Points: 0
    Rank: Member

    Hi Rob,

    Thanks man, that fixed it for me!

  • #20056

    Points: 0
    Rank: 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.