I'm trying to use the Invoke-Expression Command to run a command-line tool called VSHADOW.EXE.
The problem is, that the VSHADOW.EXE needs a parameter that includes curly braces { and } to pass a GUID.
e.g. : "vshadow.exe -el={57638930-b036-4d34-9127-073514dc29c1},S:"
When I execute it in standard CMD it works perfectly fine. But Powershell seems to have a problem with the curly braces.
I tried the following syntax that usually works for me, if there are non-standard Characters in the command:
---------------------------------------------------------
$command = (".\bin\vshadow.exe -el=" + $GUID + ",S:")
Invoke-Expression -command "& $command"
---------------------------------------------------------
I?ve put ? and ? and ` almost everywhere and I even tried to pass the curly braces by using ASCII ([char]123) but it just won?t work :-(
Most of the time I get an error message that sais something about a ?faulty numeric constant? (I?m not sure if it?s exactly the same text in English )
Anybody got an idea how to pass an command with curly braces with Invoke-Expression ??
Kind Regards,
Michael
Try:
Invoke-Expression -command "`"$command`""
--
Miles
Sorry, this might work.
$guid='{57638930-b036-4d34-9127-073514dc29c1}'
$command = ".\bin\vshadow.exe `"-el=$GUID,S:`""
Invoke-Expression "& $command"
I suggest you look at Dmitry's blog at
http://dmitrysotnikov.wordpress.com/2011/07/06/passing-parameters-to-encodedcommand/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+DmitrysPowerblog+%28Dmitry%27s+PowerBlog%29
(sorry for the long URL). It deals with passing arguments to
PowerShell from a batch file which is used to start up PowerShell and
pass it arguments using the -EncodedCommand switch to PowerShell.exe.
I found this most enlightening.
$GUID = "{6247894c-e9ac-489f-b33b-2911ec3f204d}"
Invoke-Expression ".\bin\vshadow.exe `"-el=$GUID,S:`""
I have no idea why the ` and the " have to be exactly at the positions they are, but as long as it works it's fine for me :-)
kind regards and many thanks,
Michael