任务计划程序中的 PowerShell MySQL 备份脚本错误 0x00041301

我创建了以下 PowerShell 脚本.

I have created the following PowerShell script.

$root = 'C:\Backups\My Website\Database Dumps\'

$dateString = (Get-Date).ToString("yyyy-MM-dd")

$fileName = $dateString + "-MyWebsiteDbBackup.sql"

$backupFilePath = ($root + $fileName)

$command = ("mysqldump -u root wpdatabase > " + "`"$backupFilePath`"")

Write-Host $command

Invoke-Expression $command

它的功能应该是为我的 WordPress 网站制作 MySQL 数据库的每日备份.

Its function is supposed to be making a daily backup of a MySQL database for my WordPress website.

当我在 PowerShell ISE 中运行脚本时,它运行良好,并且创建的 MySQL 转储文件没有问题.

When I run the script in PowerShell ISE, it runs fine and the MySQL dump file is created with no problems.

然而,在任务计划程序中,它被困在运行代码0x00041301.

However, in Task Scheduler, it was stuck on running with a code 0x00041301.

对于凭据,我使用了 my.cnf 技术 此处描述.而且我已经将任务设置为无论用户是否登录都运行.

For the credentials, I am using the my.cnf technique described here. And I've set the task to run whether a user is logged on or not.

代码更新

基于 vonPryz 的回答.

Based on vonPryz's answer.

$root = 'C:\Backups\My Website\Database Dumps\'

$dateString = (Get-Date).ToString("yyyy-MM-dd")

$fileName = $dateString + "-MyWebsiteDbBackup.sql"

$backupFilePath = ($root + $fileName + " 2>&1")

$command = ("mysqldump -u root wpdatabase > " + "`"$backupFilePath`"")

Write-Host $command

$output = Invoke-Expression $command 

$output | Out-File C:\mysqlBackupScriptOutput.txt

这现在给我一个错误,说路径中的非法字符

This now give me an error saying illegal character in path

我做错了什么?

推荐答案

Task Scheduler 的代码 0x00041301 意味着任务正在运行.这可能意味着 mysqldump 正在提示某些东西.也许是密码或一些确认对话框.正在运行任务的用户帐户是哪个?

Task Scheduler's code 0x00041301 means that the task is running. This is likely to mean that mysqldump is prompting for something. Maybe a password or some confirmation dialog. Which user account is the task being run on?

为了调试,您需要捕获进程的输出以查看发生了什么.尝试使用 Tee-Object 发送一个复制到文件中.

In order to debug, you'd need to capture the process' output to see what's going on. Try using Tee-Object to send a copy to a file.

相关文章