Running SQLCMD in a Powershell script

Hi,

I’m running a simple SQLCMD in a new set up of Octopus on a listening tentacle.
“D:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\sqlcmd.exe” -S $DatabaseServer -E -b -v DBName="$CustomerDatabaseDWCS" -v NewServer="$DatabaseServer" -v NewDatabase="$CustomerDatabaseDWH" -i"D:\TeamCity\SQLScripts\UpdateCPForNewServerName.sql"

All the sql does is update some rows on a table.
At C:\Octopus\Work\20180705103947-1312-21\Script.ps1:1 char:83
July 5th 2018 11:39:49
Error

  • … soft SQL Server\Client SDK\ODBC\130\Tools\Binn\sqlcmd.exe" -S $Databa …
    July 5th 2018 11:39:49
    Error
  •                                                            ~~ 
    

July 5th 2018 11:39:49
Error
Unexpected token ‘-S’ in expression or statement.
July 5th 2018 11:39:49
Error
At C:\Octopus\Work\20180705103947-1312-21\Script.ps1:1 char:86
July 5th 2018 11:39:49
Error

  • … Client SDK\ODBC\130\Tools\Binn\sqlcmd.exe" -S $DatabaseServer -E -b - …
    July 5th 2018 11:39:49
    Error
  •                                               ~~~~~~~~~~~~~~~ 
    

July 5th 2018 11:39:49
Error
Unexpected token ‘$DatabaseServer’ in expression or statement.
July 5th 2018 11:39:49
Error
At C:\Octopus\Work\20180705103947-1312-21\Script.ps1:1 char:102
July 5th 2018 11:39:49
Error

  • … ent SDK\ODBC\130\Tools\Binn\sqlcmd.exe" -S $DatabaseServer -E -b -v D …
    July 5th 2018 11:39:49
    Error
  •                                                            ~~ 
    

July 5th 2018 11:39:49
Error
Unexpected token ‘-E’ in expression or statement.
July 5th 2018 11:39:49
Error
At C:\Octopus\Work\20180705103947-1312-21\Script.ps1:1 char:105
July 5th 2018 11:39:49
Error

  • … SDK\ODBC\130\Tools\Binn\sqlcmd.exe" -S $DatabaseServer -E -b -v DBNa …
    July 5th 2018 11:39:49
    Error
  •                                                            ~~ 
    

July 5th 2018 11:39:49
Error
Unexpected token ‘-b’ in expression or statement.
July 5th 2018 11:39:49
Error
+ CategoryInfo : ParserError: (:slight_smile: [], ParentContainsErrorRecordException
July 5th 2018 11:39:49
Error
+ FullyQualifiedErrorId : UnexpectedToken
July 5th 2018 11:39:49
Error

July 5th 2018 11:39:49
Fatal
The remote script failed with exit code 1
July 5th 2018 11:39:49
Fatal
The action Update Data for Customer Source information on DEVSQL20SH01 (Customer) failed

With the correct values (those passed in) the command runs fine using a cmd window, but gives the same error in Powershell. Have you any ideas why this would be? It runs ok in powershell from TeamCity on a separate server.
Cheers,
Anthony

Hi Anthony,

Thanks for getting in touch! I may have a quick fix for this issue. It was pointed out by a colleague that the command you are running could be missing a leading &.

Example:

& "C:\path\thing.exe" -parameter1 value1 -parameter2 value2

If this does not help you resolve your issue, would you be able to upload as an attachment, a full deployment log with variable logging enabled?

Looking forward to hearing from you and getting to the bottom of this. :slight_smile:

Best regards,
Daniel

1 Like

Yep, that was the change I made.

Thanks

Hi Anthony,

Thanks for the update here, I’m glad to hear you resolved your issue. :slight_smile:

Please don’t hesitate to get in touch at any time.

Best regards,
Daniel

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.