2

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 ?

Here's my code :

$expirationDate = Get-Date
$expirationDate = $expirationDate.AddDays($expirationDelayInDays)

Backup-SqlDatabase -ServerInstance $serverInstance -Database $database -ConnectionTimeout 0 -BackupFile $outputFile -ExpirationDate $expirationDate
6
  • According to the documentation expirationdate should be of type DateTime. However, it seems you're not updating the $expirationDate on your second line. Could you try: $expirationdate = $expirationdate.adddays($expirationDelayInDays) Commented Jun 17, 2013 at 10:16
  • You're right, I changed the code... not better. $expirationDate is DateTime I believe. Commented Jun 17, 2013 at 10:50
  • Strange as the code works for me, what value are you using for the variable $expirationDelayInDays? It may be that rather than a formatting issue, the value you are passing is indeed invalid as a datetime is definitely the only type this parameter will accept. Commented Jun 17, 2013 at 12:57
  • I use 7 for $expirationDelayInDays. To me $expirationDate is a datetime, am I wrong ? Commented Jun 17, 2013 at 14:40
  • OK. It seems that $expirationdate should not be of DateTime type ! ... but a string that can be converted into a datetime. When using $expidationdate = "2013-09-01" it works...but I believe there is a bug in the convesion so that 09 and 01 are inverted. Commented Jun 20, 2013 at 9:44

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.