Pregunta

I have a little problem with my Powershell backupscript. I use the Task Scheduler with Robocopy to deploy my backups.

This is an example of a command:

schtasks /Create /SC ONCE /TN $TaskName /TR "robocopy.exe $Source $Target /E /COPY:DAT /V /R:0 /W:0 /LOG+:$LogPfad" /ST $StartTime /SD $StartDate /F

The problem is, that when I run my script, the task will appear, but it uses the same text with the same variables

For example, this script will run the task with this command:

robocopy.exe $Source $Target /E /COPY:DAT /V /R:0 /W:0 /LOG+:$LogPfad

So that the Backup can't run properly.

It should be saved in the task like this:

robocopy.exe C:\test\source D:\test\target /E /COPY:DAT /V /R:0 /W:0 /LOG+:$LogPfad

There is an option, that I could save the command in a .bat file and execute it, but this shouldn't be the solution.

Would be fantastic, if somebody could help me! :D

Best regards

lucbas

¿Fue útil?

Solución

Looking at your code you might want to try something like this:

schtasks /Create /SC ONCE /TN $TaskName /TR `"robocopy.exe $QuellPfadRAW $ZielPfad /M /E /COPY:DAT /V /R:0 /W:0 /LOG:$LogPfad`" /ST $StartTime /SD $StartDate /F

When you put "s in a Powershell line it takes everything inside of them as literal, meaning variables won't be replaced.

If you put a ` in front of each of your "s it should negate that.

Sorry it took me so long to get back to you btw.

Otros consejos

how about

$taskrun = "`"robocopy.exe $Source $Target /E /COPY:DAT /V /R:0 /W:0 /LOG+:$LogPfad" /ST $StartTime /SD $StartDate`""
schtasks /Create /SC ONCE /TN $taskrun
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top