Invoke-Async to deploy SQL script on multiple servers.

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

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 8 months ago.

  • Author
    Posts
  • #67983

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

    Keymaster
    Points: 1,704
    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.

The topic ‘Invoke-Async to deploy SQL script on multiple servers.’ is closed to new replies.