0

I'm attempting to create a scheduled task on Windows Server 2012 that will execute a powershell script that will create an archive of a specific directory once per day.

The arguments to execute the script should be as follows (via command line): .\CreateBackup.ps1 -BackupTarget "D:\SOFT_DIST\Production\_New_Build\Documentation\Windows Build Documentation\" -BackupDestination "D:\SOFT_DIST\Production\_New_Build\Documentation\Build Documentation Backups\Backups\" -DeleteOutdatedFiles $true -FileTTLDays 30

The script works perfectly fine, however the issue is when I input the arguments into Task Scheduler, I receive an error stating "D:\SOFT_DIST\Production_New_Build\Documentation\Build is not recognized as the name of a cmdlet, function, script file, or operable program." . Keep in mind that in actuality , the directories are valid.

In Task Scheduler, this is what I have entered under Actions (pulled from the XML export file)

<Command>powershell.exe</Command>
  <Arguments>
    -ExecutionPolicy Bypass "D:\SOFT_DIST\Production\_New_Build\Documentation\Build Documentation Backups\CreateBackup.ps1" 
    -BackupTarget 'D:\SOFT_DIST\Production\_New_Build\Documentation\Windows Build Documentation\'
    -BackupDestination 'D:\SOFT_DIST\Production\_New_Build\Documentation\Build Documentation Backups\Backups\' 
    -DeleteOutdatedFiles $true
    -FileTTLDays 30
  </Arguments>

Based on this, what should I fix to get this script to execute via a Scheduled Task? I believe the issue lies with spaces in the directory paths.

Daniel
  • 121
  • 5
  • 1
    [1] have you tried adding an outer set of single quotes? something like `'"d:\ThingOne\Phrase With Embedded Spaces"'`. note the outer quotes are singletons - so it goes `single quote`, `double quote`, `string`, `double quote`, `single quote`. ///// [2] are you allowed to get rid of the [annoyingly problematic] spaces? – Lee_Dailey Sep 28 '21 at 20:26
  • @Lee_Dailey unfortunately I can't get rid of them. I tried what you suggested, but no luck: `powershell.exe -ExecutionPolicy Bypass '"D:\SOFT_DIST\Production\_New_Build\Documentation\Build Documentation Backups\CreateBackup.ps1"' -BackupTarget '"D:\SOFT_DIST\Production\_New_Build\Documentation\Windows Build Documentation\"' -BackupDestination '"D:\SOFT_DIST\Production\_New_Build\Documentation\Build Documentation Backups\Backups\"' -DeleteOutdatedFiles $false -FileTTLDays 30` – Daniel Sep 28 '21 at 20:48
  • arg! [*frown*] have you tried putting the `powershell.exe` in the action slot named `program/script` and then putting the entire argument line into the action slot named `add arguments`? folks often put the entire thing in the `program/script` slot ... and that has problems. – Lee_Dailey Sep 29 '21 at 13:49

0 Answers0