Calling Invoke-Sqlcmd from powershell and passing an object containing a '-'

  • Invoke-Sqlcmd  -Query "ALTER AVAILABILITY GROUP $AAG REMOVE DATABASE $DB " -ServerInstance $Instance
    Invoke-Sqlcmd : Incorrect syntax near '-'.
    Msg 102, Level 15, State 1, Procedure , Line 1.

    Hello all,

    As you can see from the sample above $AAG contains 'MY-AG' (not the real AG name but the hyphen is in the name) results in SQL interpreting (presumption on my part) the - as a parameter delimiter????  Any ideas, suggestions or proven methods to overcome this?  Many thanks for your help

     

     

  • put both around square brackets e.g. [$AAG] and [$DB]

  • Thank you Frederico,

    Can you please point me to where I can read/learn more on this?  Searched for documentation and it seem lacking. Thank you

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply