mehnihma mehnihma - 1 year ago 274
PowerShell Question

Powershell SQLCMD Mode error

I am trying to run PowerShell Invoke-Sqlcmd but I get an error:

Invoke-Sqlcmd -MaxCharLength 100000 -ServerInstance server1\darabse -InputFile \\server\query.sql

Invoke-Sqlcmd :
At line:6 char:1
+ Invoke-Sqlcmd -MaxCharLength 1000000 -ServerInstance server\database ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Sqlcmd], ParserException
+ FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

I can run in in Management studio with SQLCMD Mode.

I have tried everything form here . Any ideas? There is no "$" within it.

I succeed to do i like this, but I am not sure this is solution?

sqlcmd -i \\server\Shared\install\file.sql


Answer Source

it works like this:

cmd.exe /C sqlcmd -i \\share\Shared\install_scripts\02SQL\create.sql
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download