I have step template that has the following line of code:
Powershell.exe -Command “& {Add-PSSnapin SqlServerCmdletSnapin100;Add-PSSnapin SqlServerProviderSnapin100;$InvokeSQLcmd}” > $LogFilePath
I have copied this step Module to a ps1 file and ran it on target server with no error. But when I run it in Octopus deploy it comes up with the following error:
Unexpected token ‘&’ in expression or statement.
At D:\Octopus\Work\20160609152033-429\Script.ps1:36 char:31
Powershell.exe -Command “& <<<< {Add-PSSnapin SqlServerCmdletSnapin100;Add-PSSnapin SqlServerProviderSnapin100;$InvokeSQLcmd}” > $LogFilePath
+ CategoryInfo : ParserError: (&:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
The remote script failed with exit code 1
There is a limitation in Powershell 2.0 where it cannot take the output from Invoke-sqlcmd to a file.
Yes, I have tried your method and it does not work.
The work around that I have found is that we run powershell.exe and send the result out to a file.
Any reason why I am unable to run powershell.exe –command “& {$InvokeSQLcmd}”?
Regards
Binh Au
Senior Release Analyst, Service Delivery
ILS Commercial Delivery & Technology