Search code examples
powershellinvoke-command

Losing elements in array invoke-command


I'm calling a powershell script thus:

function checkUrlOnSites([string[]]$urls) {
    #1
    Write-Verbose $urls.count
    $results=invoke-command -computername $computerName -ea silentlycontinue 
               -ev errRemote -scriptblock ${function:checkUrlOnSite} -args $urls
}


function checkUrlOnSite([string[]]$urls)
{
    #2
    Write-Verbose $urls.count
}

The first Write-Verbose writes 2 the second writes 1? what am I missing here? Where's my other string disappearing to??


Solution

  • change in this way:

    $results=invoke-command -computername $computerName -ea silentlycontinue `
                   -ev errRemote -scriptblock ${function:checkUrlOnSite} -argumentlist (,$urls)
    

    You need to force the argument as an array with the comma notation (,$urls)