0

I'm new to powershell and can't figure why I get the following error

Invoke-Command : A positional parameter cannot be found that accepts argument 'D:\Deploy\file.zip'. At D:\source\Scripts\Build-Deploy\Build-Deploy\ServersDeploy.ps1:105 char:5

  • Invoke-Command -ComputerName $servers -ScriptBlock {
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand

This is the script being run

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

1 Answer 1

4

Because you separated the arguments with spaces instead of a comma. That makes them new arguments to Invoke-Command.

-ArgumentList a single parameter that takes an array:

Invoke-Command -ComputerName $servers -ScriptBlock {
    # Stuff
} -ArgumentList $dest_package_path,$src_package_path,$deploy_script
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.