Invoke-Async to deploy SQL script on multiple servers.

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 year, 2 months ago.

  • Author
  • #67983


    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

    Don Jones

    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.

You must be logged in to reply to this topic.