Using $dirfiles variable with -Parameters

Hello I have an issue using the $dirfiles variable in a parameter.

Execute-Process -Path 'C:\Windows\System32\dism.exe' -Parameters '/Online /Add-Package /PackagePath:$dirfiles\Windows6.1-KB2786081-x64.cab /quiet /norestart /LogPath:C:\temp\PSAPP\Patches\KB2786081_Install.log' -PassThru

The issue is $dirfiles resolves to C:\Program Files\blah\blah

When the parameters are passed to dism quotes are not included in the path. Is there a way to have $dirfiles always include quotes in its path?

When using a variable in the parameters section you need to change the quote style like this -Parameters “/s /f1^”$dirFiles\desktop.iss^"" The ^ are actually the ` key left of the 1 key it formats it out on the post.

Thank you that helped I initially tried the proposed solution. I was just using the wrong key.

1 Like

Thank you so much! I have been fighting this for a week. Your answer solved the problem.