Invoke-Async to deploy SQL script on multiple servers.

Welcome Forums General PowerShell Q&A Invoke-Async to deploy SQL script on multiple servers.

Viewing 1 reply thread
  • Author
    • #67983
      Topics: 6
      Replies: 7
      Points: 0
      Rank: Member

      I’m trying to use invoke-Async to deploy a SQL script to multiple sql servers.

      The invoke-async code is here.
      The script uses invoke-sqlcmd2, the code for which is here.

      The following non-sql-server-code works.

        $sb = [scriptblock] {param($system) gwmi win32_operatingsystem -ComputerName $system | select csname,caption} 
          $servers = 'Server1', 'Server2', 'Server3', 'Server4'
          $rtn = Invoke-Async -Set $servers -SetParam system  -ScriptBlock $sb

      I tweaked the code a bit (below) to work for SQL server. Doesn’t work. Obviously, I’m missing something. Any help is greately appreciated. Thank you.

       $sb = [scriptblock] {param($system) Invoke-SQLCmd2 -ServerInstance $system -ServerInstance 'select name from sys.databases'  } 
          $servers = 'Server1', 'Server2', 'Server3', 'Server4' 
          $rtn = Invoke-Async -Set $servers -SetParam system  -ScriptBlock $sb
    • #68733
      Topics: 18
      Replies: 4872
      Points: 1,903
      Helping HandTeam Member
      Rank: Community Hero

      Can you be more clear about “doesn’t work?” Is there an error? Have you tried running that same code locally against just a single computer? My guess is either permissions or something in the syntax of your command. Or, the remote machines don’t have Invoke-SQLCmd2 available.

Viewing 1 reply thread
  • The topic ‘Invoke-Async to deploy SQL script on multiple servers.’ is closed to new replies.