Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invoke-Expression with curly braces { }

648 views
Skip to first unread message

Michael Hennemann

unread,
Jul 3, 2011, 11:33:25 AM7/3/11
to
Hi!

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

Miles Willmek

unread,
Jul 7, 2011, 11:15:25 PM7/7/11
to

Try:

Invoke-Expression -command "`"$command`""

--
Miles

Miles Willmek

unread,
Jul 7, 2011, 11:48:28 PM7/7/11
to

Sorry, this might work.

$guid='{57638930-b036-4d34-9127-073514dc29c1}'
$command = ".\bin\vshadow.exe `"-el=$GUID,S:`""
Invoke-Expression "& $command"

RichB4

unread,
Jul 8, 2011, 12:29:53 PM7/8/11
to

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.

Michael Hennemann

unread,
Jul 12, 2011, 3:22:39 PM7/12/11
to
Thank You, Miles! It works!

$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


Michael Hennemann

unread,
Jul 12, 2011, 3:23:03 PM7/12/11
to

Michael Hennemann

unread,
Jul 12, 2011, 3:23:15 PM7/12/11
to
0 new messages