question

MansouriSadok-2198 avatar image
0 Votes"
MansouriSadok-2198 asked RichMatheisen-8856 answered

Escape quotes with cmd

Hello guys,

i want to run this powershell scripblock with cmd script :

Get-ScheduledTask | foreach {Export-ScheduledTask -TaskName $.TaskName -TaskPath $.TaskPath | Out-File (Join-Path “D:\Testing\Sauv\SchTasks” “$($_.TaskName).xml”)}

Like :

powershell -command “Get-ScheduledTask | foreach {Export-ScheduledTask -TaskName $.TaskName -TaskPath $.TaskPath | Out-File (Join-Path “D:\Testing\Sauv\SchTasks” “$($_.TaskName).xml”)}”

but i can’t get the result, how can i espace the quotes ?

thanx for your help

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Microsoft has a handy tool that helps you to construct (well, actually it just shows you the results; it doesn't offer any help) command line quoting. You'll find the source code here: TestExe. You'll have to compile it yourself, but you can install the free version of Visual Studio to accomplish that.

After correcting the "smart quotes" and restoring the missing "underbar" characters in your post, here is the results from testing your original string:

 "Get-ScheduledTask | foreach {Export-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath | Out-File (Join-Path "D:\Testing\Sauv\SchTasks" "$($_.TaskName).xml")}"
    
 Arg 0 is <Get-ScheduledTask | foreach {Export-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath | Out-File (Join-Path D:\Testing\Sauv\SchTasks $($_.TaskName).xml)}>

Doubling the double quotes within the data, the results look like this:

 "Get-ScheduledTask | foreach {Export-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath | Out-File (Join-Path ""D:\Testing\Sauv\SchTasks"" ""$($_.TaskName).xml"")}"
    
 Arg 0 is <Get-ScheduledTask | foreach {Export-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath | Out-File (Join-Path "D:\Testing\Sauv\SchTasks" "$($_.TaskName).xml")}>

I think that'll get you what you want.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.