Copy-Item in Scriptblock

by May 25, 2013

I'm having a problem with copy-item, here's the code,

$completePath = "n:" + $UpgradePath +"Upgrade"

Invoke-Command $server -Credential $credential -ScriptBlock{net use n: \server1Library_Upgradedir /user:me yep} # works fine, drive is mapped

Invoke-Command -comp $server1 -Cred $credential -ScriptBlock {copy-item $completePath -destination l:tempupgrade -force -Recurse} #does not work

Cannot bind argument to parameter 'Path' because it is null. 

So did the $completePath lose it's value in the scriptblock? if so how would one pass the value? It has to be a variable as the directory is input when run.

When I 'write-host $completePath' it looks good.