![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 |
My System Specs![]() |
| | #2 (permalink) |
| | 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 |
My System Specs![]() |
| | #3 (permalink) |
| | 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 |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| escape character question - hopefully an easy question | PowerShell | |||
| Re: exchange shell escape character | PowerShell | |||
| How can I escape a slash character in item name? | PowerShell | |||
| howto? escape the comment character | PowerShell | |||
| Bug in escape character / variable expansion? | PowerShell | |||