Author Posts

April 6, 2017 at 3:07 pm

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

April 14, 2017 at 1:31 pm

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.