I am creating a string that I would like to pass to the bcp command from within a PowerShell script. Here is the code that creates the string
$fullFilePath = (pwd).path + "\$db.$table" + ".dat"
$copyExecString = "bcp $db.$table out $fullFilePath -E -N -Slocalhost"
I can paste the Write-host result of this into a command prompt and it runs just fine, but it won’t work as follows:
$fullFilePath = (pwd).path + "\$db.$table" + ".dat"
$copyExecString = "$db.$table out $fullFilePath -E -N -Slocalhost"
bcp $copyExecString
I also tried using the ampersand character before calling the bcp command, but to no avail
Any ideas on how to achieve this functionality would be greatly appreciated
you can use
Invoke-Expressioncmdlet to ensure that you parse what you want to execute prior to execution: