Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Escape character question

Closed Thread
 
Thread Tools Display Modes
Old 08-06-2007   #1 (permalink)
lawndart
Guest


 

Escape character question

I have a DOS command I'm trying to run from powershell, as part of an
automation script. The problem I'm having is an "Incomplete String
Token" error when I use Invoke-Expression on it. Here are the relevant
bits:

$pwdSetString = "bemcmd.exe -o213 -
i""`{10011001-1001-1001-0101-010101010101`}"" -pw:""$oldPwd"" -
pl:""$newPwd"" -cemslbk01"

$pwdSetString

$results = Invoke-Expression -command $pwdSetString

Output
-------------------------
PS - powershell> ./set-BUEServiceAccountPwd.ps1
bemcmd.exe -o213 -i"{10011001-1001-1001-0101-010101010101}" -pw:"asd" -
pl:"asd" -cmachineName
Invoke-Expression : Incomplete string token.
At \Path\set-BUEServiceAccountPwd.ps1:16 char:29
+ $results = Invoke-Expression <<<< -command $pwdSetString
BUE Password set result:

I know that the {} characters are the issue, but they are pretty much
required in the command. This command works fine in DOS and I assumed
that escaping them would make PS happy as well. Any ideas on how to
run this?

Lawndart

Old 08-07-2007   #2 (permalink)
Oisin Grehan
Guest


 

Re: Escape character question

On Aug 6, 1:22 pm, lawndart <lawnd...@gmail.com> wrote:
> I have a DOS command I'm trying to run from powershell, as part of an
> automation script. The problem I'm having is an "Incomplete String
> Token" error when I use Invoke-Expression on it. Here are the relevant
> bits:
>
> $pwdSetString = "bemcmd.exe -o213 -
> i""`{10011001-1001-1001-0101-010101010101`}"" -pw:""$oldPwd"" -
> pl:""$newPwd"" -cemslbk01"
>
> $pwdSetString
>
> $results = Invoke-Expression -command $pwdSetString
>
> Output
> -------------------------
> PS - powershell> ./set-BUEServiceAccountPwd.ps1
> bemcmd.exe -o213 -i"{10011001-1001-1001-0101-010101010101}" -pw:"asd" -
> pl:"asd" -cmachineName
> Invoke-Expression : Incomplete string token.
> At \Path\set-BUEServiceAccountPwd.ps1:16 char:29
> + $results = Invoke-Expression <<<< -command $pwdSetString
> BUE Password set result:
>
> I know that the {} characters are the issue, but they are pretty much
> required in the command. This command works fine in DOS and I assumed
> that escaping them would make PS happy as well. Any ideas on how to
> run this?
>
> Lawndart


Try:

PS 1> $pwdSetString = { bemcmd.exe `-o213 `-
i"`{10011001-1001-1001-0101-010101010101`}" `-pwd:"$oldPwd" `-
pl:"$newPwd" `-cemslbk01 }
PS 2> $oldPwd = "blah"
PS 3> $newPwd = "pox"
PS 4> & $pwdSetString

I found that the minus sign parameter prefixes were confusing the
powershell parser as it was treating them as operators; I also changed
it to use scriptblock syntax to get rid of one layer of quotes.

Hope this helps,

- Oisin

Old 08-07-2007   #3 (permalink)
lawndart
Guest


 

Re: Escape character question

On Aug 7, 9:08 am, Oisin Grehan <ois...@gmail.com> wrote:
> On Aug 6, 1:22 pm, lawndart <lawnd...@gmail.com> wrote:
>
>
>
> > I have a DOS command I'm trying to run from powershell, as part of an
> > automation script. The problem I'm having is an "Incomplete String
> > Token" error when I use Invoke-Expression on it. Here are the relevant
> > bits:

>
> > $pwdSetString = "bemcmd.exe -o213 -
> > i""`{10011001-1001-1001-0101-010101010101`}"" -pw:""$oldPwd"" -
> > pl:""$newPwd"" -cemslbk01"

>
> > $pwdSetString

>
> > $results = Invoke-Expression -command $pwdSetString

>
> > Output
> > -------------------------
> > PS - powershell> ./set-BUEServiceAccountPwd.ps1
> > bemcmd.exe -o213 -i"{10011001-1001-1001-0101-010101010101}" -pw:"asd" -
> > pl:"asd" -cmachineName
> > Invoke-Expression : Incomplete string token.
> > At \Path\set-BUEServiceAccountPwd.ps1:16 char:29
> > + $results = Invoke-Expression <<<< -command $pwdSetString
> > BUE Password set result:

>
> > I know that the {} characters are the issue, but they are pretty much
> > required in the command. This command works fine in DOS and I assumed
> > that escaping them would make PS happy as well. Any ideas on how to
> > run this?

>
> > Lawndart

>
> Try:
>
> PS 1> $pwdSetString = { bemcmd.exe `-o213 `-
> i"`{10011001-1001-1001-0101-010101010101`}" `-pwd:"$oldPwd" `-
> pl:"$newPwd" `-cemslbk01 }
> PS 2> $oldPwd = "blah"
> PS 3> $newPwd = "pox"
> PS 4> & $pwdSetString
>
> I found that the minus sign parameter prefixes were confusing the
> powershell parser as it was treating them as operators; I also changed
> it to use scriptblock syntax to get rid of one layer of quotes.
>
> Hope this helps,
>
> - Oisin


Huh, didn't think of using a script block for that. That worked quite
well, thanks.

Lawndart

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: exchange shell escape character Bob Butler PowerShell 7 10-12-2007 02:50 PM
How can I escape a slash character in item name? KH.Lee PowerShell 5 06-08-2007 09:07 AM
How do I escape the wildcard character in a path string? Chuck Heatherly PowerShell 1 04-30-2007 08:11 AM
howto? escape the comment character public news groups PowerShell 3 11-02-2006 04:33 PM
Bug in escape character / variable expansion? =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 4 07-24-2006 04:07 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50