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.