I need to call DISM.exe via its absolute path which changes dependent on system architecture. Therefore, I store the filepath of dism.exe in a variable and then proceed to execute the wntire command via invoke-expression, like so:

$dism = "C:\Windows\sysnative\dism.exe"
invoke-expression "$dism /online /enable-feature /featurename:$index"

This is working fine. However, I also have to pipe DISM's output into a find command, so I tries this:

invoke-expression "$dism /online /get-featureinfo /featurename:$index | find `"State :`""

That gives me the error "FIND: Parameter format not correct" I tried putting the parameter-string for find into its own variable -> nothing.

How can I pass quoted strings inside a call for invoke-expression?

EDIT: Usually I would use the cmdlet-version of any DISM command (in this case I could use get-WindowsOptionalFeature). However, this script is part of an application that is rolled out via SCCM Software Center. The reason I cannot use the cmdlet version here is as folows: SoftwareCenter is a 32-bit application and thus the powershell-script is also run in 32-bit mode. I have to modify both 32- and 64-bit images. I work around this problem by launching Powershell from the hidden sysnative folder (explanation see here).
However, since I can't konw in advance wheahter the image I'm modifying is 32-bit or 64-bit, I have to check that at the beginning of my script and then I store the corresponding program path for Powershell in a variable.
Now, I know I can use invoke-expression (see code above) to call a command stored in a variable with parameters. I do not know how to do that with cmdlets, since that doesn't give me the possibility to use a custom program path. That is why I had to use the old dism.exe command. I now have a workaround for the whole situation which consists of having a "launcher" script which detect the bitness in advance and then launches my actual script with the corresponding version of Powershell.

The original issue, which is "how can I pass parameters containing quoted arguments to the invoke-expresion-command, still stands... Thank you in advance!

  • Are you using PowerShell 4.0? If so, there are DISM cmdlets you can use. Those will return objects and not strings which are easier and more accurate to manipulate/search.
    – E.V.I.L.
    Feb 10, 2015 at 17:54
  • Hi, sorry for the delayed answer. Usually I would use the cmdlet-version (i.e. get-WindowsOptionalFeature), as you said. I've edited my question, explaining why I can't do that in this case. Feb 16, 2015 at 12:08

1 Answer 1


I believe you are missing " in your find Expression

Try This

| find "`"State :`""

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.