Passing a variable to invoke-command

I am using invoke-command to run a batch file remotely, although my script is much longer, these are the relevant parts to my question

$path="c:\download\install"

$script={&cmd /c "$path"\BatchFile.bat}

invoke-command -computername $name -scriptblock $script

 

It is not passing the path correctly to the invoke-commnad cmdlet. It is actually trying to run

"$path"\BatchFile.bat   instead of c:\download\install\BatchFile.bat

I should also not that if I make $script={&cmd /c c:\download\install\BatchFile.bat}   that everything works as expected. But I have logic which determines what $path is so I really need to be able to have the variable in there.

 

 

 

I have tried all kinds of different syntax to try to get it to run correctly, but so far nothing has worked. I am really hoping someone on here might be able to help me out.

Also I am still fairly new to powershell :)

 

 

Parents
No Data
Reply Children
No Data