您能否建议如何使此脚本有效?
通过此命令在cmd中正常工作:
wbadmin start systemstatebackup 'backuptarget:"F:"' '-quiet'
它通过以下命令在运行powershell的cmd中工作:
[powershell] wbadmin start systemstatebackup 'backuptarget:"F:"' '-quiet'
但它不能在powershell脚本(backups.ps1)中运行。我混淆使用单引号和双引号。以下迭代不起作用
backup.ps1
$IFMResult2 = "WBADMIN START SYSTEMSTATEBACKUP -backupTarget:E: -quiet"
$IFMOutput2 = Invoke-Expression $IFMResult2 | out-string -stream
$IFMResult2 = "WBADMIN START SYSTEMSTATEBACKUP 'backuptarget:"F:"' '-quiet'"
$IFMOutput2 = Invoke-Expression $IFMResult2 | out-string -stream
错误是 WBADDMIN错误(Systemstatebackup):缺少选项backuptarget的值
答案 0 :(得分:1)
这对我有用,但不问原因。
$ strBackupDrive =“ D:”
$ strBackupComand ='开始备份'+ [char []] 45 +'include:C:\ Temp \'+ [char []] 45 +'backupTarget:'+ $ strBackupDrive +'-quiet'
$ errRun =启动进程wbadmin -ArgumentList $ strBackupComand -wait -NoNewWindow -PassThru
答案 1 :(得分:0)
我认为你根本不需要引用。尝试:
$Result = & WBADMIN START SYSTEMSTATEBACKUP backuptarget:F: -quiet
您还可以将参数指定为数组:
$Result = & 'WBADMIN' @('START', 'SYSTEMSTATEBACKUP', 'backuptarget:F:', '-quiet')
请注意,在$LastExitCode
完成后,您最好检查wbadmin
,以确认没有错误。例如:
$Result = & WBADMIN SYSTEMSTATEBACKUP -backupTarget:F: -quiet
if($LastExitCode)
{
# Exit code is not null, something gone wrong
}