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 what worked for me for using sqlcmd from within the powershell script using the & operator, see sample to generate a csv file:
& cmd /c "sqlcmd -S $sv -i $PROCFILE -s, -v varDB = $dbclean -o $filename"
$sv
has server name like SERVERNAME\INSTANCE
$PROCFILE
is like d:\TSTSQL\Sqlquery.SQL
$filename
is d:\TSTSQL\Desiredoutfilename.CSV
$dbclean
is a parameter passed to the sql file