【问题标题】:Powershell script in Task Scheduler - spaces and timestamp issue任务计划程序中的 Powershell 脚本 - 空格和时间戳问题
【发布时间】:2014-07-26 13:04:54
【问题描述】:

以下脚本在 Powershell 中有效,但在任务计划程序中作为操作执行时无效:

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"

请注意,我需要使用双引号才能将 $(get-date -f yyyy-MM-dd) 转换为时间戳。不适用于单引号。

任务计划程序错误消息:Copy-Item:找不到接受参数“Manage\SharedReports\Database”的位置参数。

总而言之,有谁知道如何在任务计划程序中执行包含带有空格和时间戳的路径的 Powershell 脚本?

非常感谢

【问题讨论】:

    标签: powershell windows-7 scheduled-tasks


    【解决方案1】:

    您可以调用脚本或使用-encodedcommand 参数:Using Powershell -encodedcommand to pass parameters

    【讨论】:

      【解决方案2】:

      试试这个:

      $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"
      

      【讨论】:

        猜你喜欢
        • 2022-10-19
        • 2021-03-29
        • 2020-08-07
        • 2022-12-01
        • 2019-10-31
        • 2015-07-22
        • 1970-01-01
        • 1970-01-01
        • 2013-02-11
        相关资源
        最近更新 更多