Powershell: passing parameters to a job

前端 未结 2 1668
野性不改
野性不改 2021-01-06 00:31

I have a script that requires a number of parameters:

param ([string]$FOO=\"foo\",[string]$CFG=\'\\ps\\bcpCopyCfg.ps1\', [string]$CFROM=\"none\", `
[string]$         


        
2条回答
  •  孤街浪徒
    2021-01-06 01:23

    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.

提交回复
热议问题