故障使用调用命令与脚本块和-ArgumentList
问题描述:
我是新来的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
答
因为你用空格代替逗号分隔的参数。这使他们新的论点Invoke-Command
。
-ArgumentList
接受一个阵列中的单个参数:
Invoke-Command -ComputerName $servers -ScriptBlock {
# Stuff
} -ArgumentList $dest_package_path,$src_package_path,$deploy_script