I have a string in powershell, which contains a native sqlcmd command. The command itself can be executed successfully in cmd.exe. I have difficulty in executing them in pow
This is how I build some externals command in my scripts
$scriptblock = {fullpath\sqlcmd -S `"(local)\instance1`" <# comment option -S #>`
-U a `
-P a `
-i `"c:\temp\sql.sql`" }
Invoke-Command -ScriptBlock $scriptBlock
You can then use $args variable inside it and even start it remotly.
$scriptblock = {fullpath\sqlcmd -S `"(local)\instance1`" <# comment option -S #>`
-U a `
-P a `
-i `"$($args[0])`" }
Invoke-Command -ScriptBlock $scriptBlock -argumentList "c:\temp\sql.sql" -computer "remote1"
Remark :
This allow to comment each param.
Be careful not to forget a "`" and no space after them where they are at the end of the line.