piped value in Invoke-Command

Hi All, I have this small beginners problem with piped value into Invoke-Command scriptblock.

What I have:

$ser | % {Invoke-Command -ComputerName $_ -ScriptBlock {c:\temp\app.exe -outputFile c:\temp\$_.mf3}}

and I get nothing for $_, all files are named “.mf3”

my workaround is renaming them after, which works, but doesn’t look nice on code level

$ser | % {Rename-Item "\\$_\c$\temp\.mf3" \\$_\c$\temp\$_.mf3}

That’s not quite how Invoke-Command works.

$_ only has meaning on your local computer. When the Script Block gets to the remote machine, $_ has no meaning. Look at the “Remote Variables” topic in The Big Book of PowerShell Gotchas, linked from our eBooks menu, for alternate approaches. The examples in the help for Invoke-Command also have examples, albeit with a bit less explanation than the book.