I have a script that requires a number of parameters:
param ([string]$FOO=\"foo\",[string]$CFG=\'\\ps\\bcpCopyCfg.ps1\', [string]$CFROM=\"none\", `
[string]$
Another way is to put the @ before the array. I changed the $ARGS variable to $flags to differentiate $args in the scriptblock from $flags.
$flags = @("-CFG ", $CFG, "-CSYBDB ", $SYBDB, "-CMSDB ",$MSDB, "-CFROM ", $SYBTBL, "-CTO ",$MSTBL)
If($FULL) {
$flags = $flags + " -FULL"
}
Else {
$flags = $flags + " -CCOL $($args[5]) "
}
"Argument array:"
$flags
start-job -scriptblock {powershell.exe -file '\ps\bcpCopy.ps1' $args} -ArgumentList $flags
I'm not sure what exactly you're trying to do, but this looks wrong:
start-job -scriptblock {
powershell.exe -file '\ps\bcpCopy.ps1'} -ArgumentList $ARGS
You are creating an entirely new powershell process needlessly. Try this instead:
start-job -scriptblock {
& 'c:\ps\bcpCopy.ps1' @args } -ArgumentList $ARGS
The "@args" syntax is called "splatting." This will expand the passed arguments and ensure each element is treated as a parameter. The ampersand (&) is the "call" operator.