0

I'm trying to restore RDS DB using the InvokeSQL command and there is a use case to explicitly call pwsh!

The below works a gem

Invoke-Sqlcmd -Query 'exec msdb.dbo.rds_restore_database @s3_arn_to_restore_from="arn:aws:s3:::XXX/XX/XXX.bak",@restore_db_name=mydatabase' -ServerInstance XXXXX.eu-west-1.rds.amazonaws.com -Database master -Username XXX -Password XXX

But I have a problem while executing it as pwsh -command

pwsh -Command "& {Invoke-Sqlcmd -Query 'exec msdb.dbo.rds_restore_database @s3_arn_to_restore_from="arn:aws:s3:::XXX/XX/XXX.bak",@restore_db_name=mydatabase' -ServerInstance XXXXX.eu-west-1.rds.amazonaws.com -Database master -Username XXX -Password XXX}"

The error I get is a syntax issue-

pwsh : [91mInvoke-Sqlcmd: [91mIncorrect syntax near 'arn:'. At line:1 char:1

  • pwsh -Command "& {Invoke-Sqlcmd -Query 'exec msdb.dbo.rds_restore_dat ...
  •   + CategoryInfo          : NotSpecified: ([91mInvoke-Sql...x near 'arn:'. :String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    
avocadoLambda
  • 1,332
  • 7
  • 16
  • 33
  • 1
    Quotes in quotes are always a fun combination. Try any of using double double quotes in the query, escaping them with a backlash, escaping them with a backtick and if all else fails Base64 encoding the command and using the `-EncodedCommand` parameter (I can never personally be bothered to remember all the quoting rules across platforms and shells). – Jeroen Mostert Aug 23 '21 at 11:38
  • – Jeroen Mostert I tried to see if quotes are a problem with another query and that works fine pwsh -Command "& {Invoke-Sqlcmd -Query 'exec msdb.dbo.rds_task_status @db_name="mydatabase", @task_id=8;' -ServerInstance XXXXX.eu-west-1.rds.amazonaws.com -Database master -Username XXX -Password XXX}" and that works fine.. – user12517555 Aug 23 '21 at 11:42

0 Answers0