Single quotes in the schtasks command

I am trying to use SCHTASKS to create a scheduled task on Windows. Options include single quotes. If I create my task manually, it will work. In the Windows Task Scheduler GUI, the Details (on the action tab) are displayed as follows:

powershell (New-Object System.Net.WebClient).DownloadString ('http://mywebserver/myscript.ps1\') | powershell.exe -noprofile -

However, when I enter the SCHTASKS command ...

schtasks.exe /Create /TN "My Task" /TR "powershell (New-Object System.Net.WebClient).DownloadString ('http://mywebserver/myscript.ps1\') | powershell.exe -noprofile -" /SC MINUTE /mo 60 /RL HIGHEST

Then it appears in the graphical interface (pay attention to the interpretation of one quotation to double in the first, but not in the second.

powershell (New-Object System.Net.WebClient).DownloadString ("http://mywebserver/myscript.ps1\') | powershell.exe -noprofile -

I tried to elude him, etc. (which works great for double quotes, but not for one), but doesn't seem to be able to figure this out.?!

Thanks so much for any suggestions.

+4
5

.

:

 Powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object Net.WebClient).DownloadString('https://url/to/script.ps1'))"

, schtasks, -, ( , , ).

, :

Powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object Net.WebClient).DownloadString(\"https://url/to/script.ps1\"))"

... Yay!

, schtasks ( , powershell) :

schtasks /Create /TN "My Task Name" /RU SYSTEM /SC DAILY /ST 23:00 /TR "Powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((New-Object Net.WebClient).DownloadString(\\\"https://url/to/script.ps1\\\""))\""

, url... , , .

, powershell... , :

schtasks /Create /TN "My Task Name" /RU SYSTEM /SC DAILY /ST 23:00 /TR "Powershell -NoProfile -ExecutionPolicy Bypass -Command \`"iex ((New-Object Net.WebClient).DownloadString(\\\`"https://url/to/script.ps1\\\`"))\`""

: .

, , :)

+3

PowerShell (`) escape char. . , , -%.

schtasks.exe --% /F /Create /TN "My Task" /TR "powershell (New-Object System.Net.WebClient).DownloadString('http://mywebserver/myscript.ps1') | powershell.exe -noprofile" /SC MINUTE /mo 60 /RL HIGHEST

: " PowerShell, schtasks.exe , , " -% ", ".

0

:

schtasks.exe /F /Create /TN "My Task" /SC MINUTE /mo 60 /RL HIGHEST /TR "powershell.exe -ExecutionPolicy Bypass -NoProfile -File \\UNC\to\Script.ps1"

.ps1.

, "NT AUTHORITY\SYSTEM" UNC-, .

0

, . , args.

schtasks.exe /Create /TN "My Task" /TR ""\""powershell (New-Object System.Net.WebClient).DownloadString ('http://mywebserver/myscript.ps1\') "|" powershell.exe -noprofile -\"" /SC MINUTE /mo 60 /RL HIGHEST
0

/XML- schtasks.exe - ; xml . , , xml schtasks /TR /XML.

0

All Articles