Reputation: 3
following script works in Powershell, but won't work when executed as an action in Task Scheduler:
Copy-Item -Path '\\dfs.com\Risk Manage\Daily_DB\Daily_DB.accdb' -Destination "\\dfs.com\Risk Manage\SharedReports\Database Backup 2014\Daily_DB_backup $(get-date -f yyyy-MM-dd).accdb"
Please note that I need to use double quotes in order to get $(get-date -f yyyy-MM-dd) translate into a timestamp. Doesn't work with single quotes.
Task Scheduler error message: Copy-Item : A positional parameter cannot be found that accepts argument 'Manage\SharedReports\Database'.
To sum it up, does anyone know how to execute Powershell script containing path with spaces and timestamp in it, in Task Scheduler?
Many thanks
Upvotes: 0
Views: 731
Reputation: 109
Try this:
$Datestamp = (Get-date -f yyyy-MM-dd)
Copy-Item -Path '\\dfs.com\Risk Manage\Daily_DB\Daily_DB.accdb' -Destination "\\dfs.com\Risk Manage\SharedReports\Database Backup 2014\Daily_DB_backup_$Datestamp.accdb"
Upvotes: 0
Reputation: 1674
You could either call a script or use the -encodedcommand
parameter: Using Powershell -encodedcommand to pass parameters
Upvotes: 0