2017-03-10 34 views
0

我是新來的PowerShell和想不通,爲什麼我收到以下錯誤故障使用調用命令與腳本塊和-ArgumentList

調用命令:位置參數無法找到接受參數 「d :\部署\ file.zip」。 在d:\源\腳本\內置部署\內建部署\ ServersDeploy.ps1:105焦炭:5

  • 調用命令-ComputerName $服務器-ScriptBlock {
  • ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo:InvalidArgument:(:) [調用-命令],ParameterBindingException
    • FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand

這是腳本正在運行

params([string[[]]$servers, [string]$dest_package_path, [string]$src_package_path,[string]$deploy_script) 

Invoke-Command -ComputerName $servers -ScriptBlock { 
    param($dest_package_path,$src_package_path,$deploy_script) 
    Write-Output "Destination path = $dest_package_path" 
    Write-Output "Copying zip $src_package_path to the destination host" 
    New-Item -ItemType Directory -Force -Path $dest_package_path 
    Write-Output "Directory Created" 
    Copy-Item -Path $src_package_path -Destination $dest_package_path -Force   

    Write-Host "Copying remote deploy scripts to the destination host" 
    Copy-Item -Path $deploy_script -Destination $dest_package_path -Force 
} -ArgumentList $dest_package_path $src_package_path $deploy_script 

回答

4

因爲你用空格代替逗號分隔的參數。這使他們新的論點Invoke-Command

-ArgumentList接受一個陣列中的單個參數:

Invoke-Command -ComputerName $servers -ScriptBlock { 
    # Stuff 
} -ArgumentList $dest_package_path,$src_package_path,$deploy_script