How is it possible to use the parameters collected in a hash table for use with ArgumentList
on Invoke-Command
?
$CopyParams = @{
Source = 'E:\DEPARTMENTS\CBR\SHARE\Target'
Destination = 'E:\DEPARTMENTS\CBR\SHARE\Target 2'
Structure = 'yyyy-MM-dd'
}
Invoke-Command -Credential $Cred -ComputerName 'SERVER' -ScriptBlock ${Function:Copy-FilesHC} -ArgumentList @CopyParams
Whatever I try, it's always complaining about the 'Source':
Cannot validate argument on parameter 'Source'. The "Test-Path $_" validation script for the argument with
value "System.Collections.Hashtable" did not return true. Determine why the validation script failed
This blog talks about a similar problem, but I can't get it to work.
The same is true for a simple Copy-Item
within Invoke-Command
, example:
Invoke-Command -Credential $Cred -ComputerName 'SERVER' -ScriptBlock {Copy-Item} -ArgumentList @CopyParams
Invoke-Command : Missing an argument for parameter 'ArgumentList'. Specify a parameter of type 'System.Obj
ect[]' and try again.
At line:11 char:89
+ ... ck {Copy-Item} -ArgumentList @CopyParams
Thank you for your help.
ScriptBlock
- assume that's what's pullingargs[0]
and expecting it to be a hash? Also assume that's where the error message comes from? – LorileeScriptBlock
is just a function with in the parameters aTest-path
on[String]Source
and[String]Destination
. After this it just usesCopy-Item
to copy stuff. It works fine when passing them as-ArgumentList $Source, $Destination
, but not with splatting. – ColdshoulderCopy-Item
, you'll see it doesn't work. Not even with the dollar sign. – Coldshoulder