I have a short Powershell script:
$spName = $args[0]
$filterList = $args[1]
$destinationFile = $args[2]
$server = $args[3]
$user = $args[4]
$password = $args[5]
bcp "EXEC $spName @FilterList = $filterList" queryout "$destinationFile" -c -t"\0" -S $server -U $user -P $password
I am using the Powershell object in .Net to add the arguments and call the Invoke method. I had a problem, though, when the password was wrong. It locked the DB down. Much embarrassment. At no point, however, was an exception thrown. I know that the .Net Pipeline object has an Error method that returns a collection of errors, but I don't know how I would implement a pipeline with this script. Is there a command for bcp? Do I just add that script as a command? Otherwise, is there a way to implement error handling with the powershell object? Any help you guys and gals can offer will be appreciated.