I'm trying to create a powershell script that creates a database. The relevant part of the createDb.ps1 is:
param([string] $server,
[string] $dbName)
$scriptpath = "C:\script\path"
$cDb = "master"
$line = "script.sql"
$outfile = "\log.txt"
$dbDir = "C:\database path\"
$command = @"
sqlcmd -b -S $server -d $cDb -i '$scriptpath\$line' -o '.$outfile' -v dbLocation='$dbDir' dbName=$dbName
"@
Invoke-Expression $command
I call the script with the following parameters:
createDb.ps1 -server localhost -dbName TestDb
However when I run this I get the following error:
sqlcmd: 'dbDir=C:\database path\" dbName=TestDb': Invalid argument. Enter '-?' for help.
When I execute the following from the command line, everything works as expected:
sqlcmd -b -S localhost -d master -i "C:\script\path\script.sql" -o ".\log.txt" -v dbLocation="C:\database path\" dbName=TestDb