Invoke-Async to deploy SQL script on multiple servers.

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 2 months, 2 weeks ago.

  • Author
    Posts
  • #67983
    Profile photo of ravilobo
    ravilobo
    Participant

    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
        $rtn

    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
        $rtn
  • #68733
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.