You can have it
return just the date or the time or both the date and the time. The format and the uformat parameters
can be used to return a standard or customized formatted date and time.
The New-TimeSpan cmdlet returns the difference between the two times that are passed to it. The
New-TimeSpan cmdlet has the following syntax:
New-TimeSpan [[-start] < DateTime > ] [[-end] < DateTime > ] [ < CommonParameters > ]
New-TimeSpan [-days < int > ] [-hours < int > ] [-minutes < int > ] [-seconds < int > ]
[ < CommonParameters > ]
There are two ways to use New-TimeSpan . One is to create an object that represents a time span and the
other is the way we are using it in our example, to determine the time span between two dates.
In the following script the current time is passed using Get-Date and then the date that the last backup
ran is passed to determine the time that has elapsed since the last full backup completed. Finally, the
script tests whether that time is greater than two days and if it is, it sends an email with information
about the database that has not had a successful backup in the last two days.
Part IV: Automating Administration
484
$results = Get-MailboxDatabase -Status | Select-Object Identity, LastFullBackup
foreach ($objItem in $results)
{
$timesincelastbackup = New-TimeSpan $($objItem.
Pages:
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672