Powershell:Backup-SqlDatabase -ExpirationDate [英] Powershell : Backup-SqlDatabase -ExpirationDate
本文介绍了Powershell:Backup-SqlDatabase -ExpirationDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将管理单元Backup-SqlDatabase与expirationDate一起使用,但出现错误:参数EXPIREDATE的值无效.有人可以告诉我如何格式化此参数吗?
I try to use the snap-in Backup-SqlDatabase with an expirationDate, and I get an error : invalid value for the parameter EXPIREDATE. Can someone tell me how to format this parameter ?
这是我的代码:
$expirationDate = Get-Date
$expirationDate = $expirationDate.AddDays($expirationDelayInDays)
Backup-SqlDatabase -ServerInstance $serverInstance -Database $database -ConnectionTimeout 0 -BackupFile $outputFile -ExpirationDate $expirationDate
推荐答案
EXPIREDATE
仅处理日期.它不处理 time 组件.因此,您需要指定一个带有空时间部分的 DateTime
(使用 DateTime.Date
属性):
EXPIREDATE
only handles dates. It does not handle time components.
Therefore, you need to specify a DateTime
with an empty time component (using the DateTime.Date
property):
$expirationDate = (Get-Date).AddDays($expirationDelayInDays).Date
Backup-SqlDatabase -ServerInstance $instance -Database $database -ExpirationDate $expirationDate
这篇关于Powershell:Backup-SqlDatabase -ExpirationDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文