Double quotes inside double quotes issue

I need to run this code in command prompt. The problem is that I need to use double quotes for $env:windir path but that doesn’t work. Is there a workaround?

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -command “& {$Taskpath = $ENV:windir\system32\Tasks;$TasksToday = Get-ChildItem -Path $TaskPath -Recurse ;}


I know it may sound silly but to “escape” double quotes you simply wrap them in double quotes. :wink:

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -command "& {$Taskpath = """$ENV:windir\system32\Tasks""";$TasksToday = Get-ChildItem -Path $TaskPath -Recurse  }"

BTW: When you post code or error messages or sample data or console output format it as code using the code tags “PRE” you find in the edit bar in the “Text” view, please. When you use the “Visual” view you can use the format template “Preformatted”. Thanks in advance.

Or make it a sum of two strings:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -command "& {$Taskpath = $ENV:windir + '\system32\Tasks';$TasksToday = Get-ChildItem -Path $TaskPath -Recurse}"

Assuming you’re in cmd:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile ^
  -command $Taskpath = $ENV:windir + '\system32\Tasks'; $TasksToday = ^
  Get-ChildItem -Path $TaskPath -Recurse


powershell -nop $taskstoday = dir $env:windir\tasks -r

Great! Thank you Olaf & Js. Both solutions work.

@Olaf, I will follow your directions about posting.