Liam
Liam

Reputation: 29694

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??

Upvotes: 1

Views: 121

Answers (1)

CB.
CB.

Reputation: 60918

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)

Upvotes: 1

Related Questions