Are you using SqlConnection and SqlCommand objects, etc, to execute sql? Or
do you want to execute sqlcmd.exe with that sql text? I'm not sure of the
specifics of your question.
regarding
$cmdtext = Get-Content (".\" + "sqlquery.sql")
if your sql is on multiple lines, you'd need to combine the lines (which are
represented in the $cmdtext array) before passing it to the sql processor.
Or, you could use:
$cmdtext = [System.IO.File];:ReadAllText(filename)
in which case $cmdText will be a scalar, not an array.
"sylan" wrote:
> Hi,
> I'm trying to read in the contents of a .sql file and use that as the query
> for my script but not having much luck in a ps1 script. Can anyone give me
> pointers?
>
> $cmdtext = Get-Content (".\" + "sqlquery.sql")
> cmd.commandtext = $cmdtext
>
> Also, any pointers to beginner level PS scripting references would be great.