ManyRootsofAllEvil
ManyRootsofAllEvil

Reputation: 523

invoke-expression inside scriptblock of invoke-command not working

I've got the following script

$name = (Invoke-Command -ComputerName "STW111" -Credential $cred -ScriptBlock { Invoke-Expression "C:\PSS\User Tool\UserTool.exe"} -AsJob).Name

Wait-Job -Name $name

This not working, however, if I move the usertool to c:\pss\, it works fine.

$name = (Invoke-Command -ComputerName "STW111" -Credential $cred -ScriptBlock { Invoke-Expression "C:\PSS\UserTool.exe"} -AsJob).Name

Wait-Job -Name $name

I really need to get to grips with escaping in Powershell.

Any ideas?

TIA

Upvotes: 0

Views: 3618

Answers (1)

CB.
CB.

Reputation: 60910

try this:

Invoke-Expression "& 'C:\PSS\User Tool\UserTool.exe'"

Upvotes: 2

Related Questions