Powershell scripting (Connection to SQL through SMO and insert data in table)

Welcome Forums General PowerShell Q&A Powershell scripting (Connection to SQL through SMO and insert data in table)

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

 
Participant
1 year, 8 months ago.

  • Author
    Posts
  • #66903

    Participant
    Points: 0
    Rank: Member

    Say I have a list of values in $result. I need to loop through and insert the all the values in a table(already created) in mssql through an SMO connection. Could you help me with the script?

  • #67053

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    Sure. Use a ForEach loop to loop through $result.

    ForEach ($thing in $result) { }

    Then fire off your INSERT statements. In this case, you can use $thing to construct query strings. I don't use SMO (I tend to just use .NET's SqlClient classes), so hopefully you know how to do that in SMO.

  • #66909

    Participant
    Points: 91
    Rank: Member

The topic ‘Powershell scripting (Connection to SQL through SMO and insert data in table)’ is closed to new replies.