Best practices for outputting objects (Inserting via invoke-SQLCMD)

Welcome Forums General PowerShell Q&A Best practices for outputting objects (Inserting via invoke-SQLCMD)

This topic contains 0 replies, has 1 voice, and was last updated by  cmac76 7 months, 2 weeks ago.

  • Author
  • #142160

    Topics: 3
    Replies: 8
    Points: 81
    Rank: Member

    Hi all,

    I am after some advice from the community with regards to how best handle the following Scenario:

    In reference to the following Best Practices when writing PowerShell tools

    *A Tool does one thing.
    *Objects are the only form of pipeline output emitted.

    I have written a tool to Insert data into a SQL Database via Invoke-SQLCMD (I am generalizing the code and removing a lot of itĀ  to protect identity)

    $ComputerName = "ServerA"
    $Geolocation = "ACountry"
    Invoke-Sqlcmd -Database $Database -ServerInstance $ServerInstance -Query "Insert into Details(ComputerName, Geolocation) VALUES ('$ComputerName','$Geolocation')"

    When this runs you get no feedback from PowerShell and I cant see anything I can use on the pipeline- but it certainly is adding data into the DB, so something is happening there.... I am aware of new parameters with invoke-sqlcmd like -outputasĀ  but playing around with these gives me nothing.

    How do I design the above so that it outputs objects.. but also not adding any extra activities in the tool..

The topic ‘Best practices for outputting objects (Inserting via invoke-SQLCMD)’ is closed to new replies.