Subtracting one DateTime object from another DateTime object returns a TimeSpan object. For example:
PS C:\Azure> $b - $a Days : 0 Hours : 0 Minutes : 28 Seconds : 7 Milliseconds : 16 Ticks : 16870168007 TotalDays : 0.0195256574155093 TotalHours : 0.468615777972222 TotalMinutes : 28.1169466783333 TotalSeconds : 1687.0168007 TotalMilliseconds : 1687016.8007 $DeltaDays is a TimeSpan object. $DeltaDays.TotalDays returns the TotalDays property of the $DeltaDays object. You may want to use $DeltaDays.Days instead. But I don't think it rounds. ________________________________ From: [email protected] <[email protected]> on behalf of Jesse Rink <[email protected]> Sent: Thursday, December 3, 2015 9:34 AM To: [email protected] Subject: [NTSysADM] Re: Powershell/scripting Oops sorry, yes, echo $BackupStatus|Select-Object -ExpandProperty LastSuccessfulBackupTime is correct... i was typing it out by hand since my copy/paste wasn't working. Can you clarify what this does, $DeltaDays.TotalDays ? Jesse Rink Source One Technology, Inc. HP Partner 262 993 2231 ________________________________ From: [email protected] <[email protected]> on behalf of Michael B. Smith <[email protected]> Sent: Thursday, December 3, 2015 8:19 AM To: [email protected] Subject: [NTSysADM] Re: Powershell/scripting Are you certain this is the right line? echo $LastSuccessfulBackupDate|Select-Object -ExpandProperty LastSuccessfulBackupTime This seems more likely: echo $BackupStatus|Select-Object -ExpandProperty LastSuccessfulBackupTime If so $LastDate = $BackupStatus.LastSuccessfulBackupTime $DeltaDays =(Get-Now - $LastDate) $DeltaDays.TotalDays Of course, no error correction detection remediation there. ________________________________ From: [email protected] <[email protected]> on behalf of Jesse Rink <[email protected]> Sent: Thursday, December 3, 2015 9:11 AM To: [email protected] Subject: [NTSysADM] Powershell/scripting Hello. I couldn't script my way out of a paperbag so, I'm looking for help if anyone on here is decent with Powershell/scripting. I'm running the following command via a Powershell script. ------ $DEVICE=$args[0] $BackupStatus = Invoke-Command -Computername $DEVICE -ScriptBlock { add-Pssnapin Windows.serverbackup -ErrorAction SilentlyContinue; Get-WBSummary } echo $LastSuccessfulBackupDate|Select-Object -ExpandProperty LastSuccessfulBackupTime ------ That result yields the following, for example, "Friday, December 1st, 2015 9:00:38 PM" How can I have Powershell take that result, and have that date Subtracted from the Current Date, and the answer be a plain integer? Something to the affect of $DaysSinceLastSuccessfulBackup=($LastSuccessfulBackupDate-%DATE%) So for example, if on December 3rd, the last successful backup was December 1st, the $DaysSinceLastSuccessfulBackup would be an integer of 2. Pardon my obvious ignorance with Powershell and coding.! Is this easily doable? Thanks. J
