How do I include a locally defined function when using PowerShell’s Invoke-Command for remoting?

You need to pass the function itself (not a call to the function in the ScriptBlock). I had the same need just last week and found this SO discussion So your code will become: Invoke-Command -ScriptBlock ${function:foo} -argumentlist “Bye!” -ComputerName someserver.example.com -Credential [email protected] Note that by using this method, you can only pass parameters into … Read more

How do I pass a local variable to a remote `Invoke-Command`? [duplicate]

In PowerShell 4 (3+ actually) the easiest way is to use the Using scope modifier: Invoke-Command -ComputerName winserver -ScriptBlock { Get-FileHash E:\test\$Using:dest.zip -Algorithm SHA1 } For a solution that works with all versions: Invoke-Command -ComputerName winserver -ScriptBlock { param($myDest) Get-FileHash E:\test\$myDest.zip -Algorithm SHA1 } -ArgumentList $dest