문제

우리는 변수가있는 배열을 만들고 스크립트로 확장 된 것으로이 배열을 전달하여 시작 작업에 의해 실행됩니다.그러나 실제로 실패하고 우리는 그 이유를 찾을 수 없습니다.어쩌면 누군가가 도울 수 있습니다!?

$arguments= @()
$arguments+= ("-Name", '$config.Name')
$arguments+= ("-Account", '$config.Account')
$arguments+= ("-Location", '$config.Location')

#do some nasty things with $config

Start-Job -ScriptBlock ([scriptblock]::create("& .'$ScriptPath' [string]$arguments")) -Name "Test"
.

와 함께 실패합니다.
Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [Select-AzureSubscription], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
    + PSComputerName        : localhost
.

$ config.name이 올바르게 설정되었지만

아이디어가 있습니까?

미리 감사드립니다!

도움이 되었습니까?

해결책

이름이 지정된 매개 변수를 전달하기 위해이 방법을 사용합니다.

$arguments = 
@{
   Name     = $config.Name
   Account  = $config.Account
   Location = $config.Location
}

#do some nasty things with $config

Start-Job -ScriptBlock ([scriptblock]::create("&'$ScriptPath'  $(&{$args}@arguments)")) -Name "Test"
.

로컬로 실행중인 경우 스크립트에 스크립트에 사용할 수있는 동일한 매개 변수 해시를 사용할 수 있습니다.

이 비트 의이 코드 :

$(&{$args}@arguments)
.

확장 가능한 문자열에 내장 된 것은 매개 변수를 생성합니다.

$config = @{Name='configName';Account='confgAccount';Location='configLocation'}
$arguments = 
@{
   Name     = $config.Name
   Account  = $config.Account
   Location = $config.Location
}

"$(&{$args}@arguments)"

-Account: confgAccount -Name: configName -Location: configLocation
.

다른 팁

단일 인용문은 리터럴 문자열 기호이며, "-name"인수를 String $config.Name 문자열에 설정합니다.값을 사용하려면 다음을 사용하십시오.

$arguments= @()
$arguments+= ("-Name", $config.Name)
$arguments+= ("-Account", $config.Account)
$arguments+= ("-Location", $config.Location)
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top