After decades of programming and multiple languages, all the syntax becomes a blur of similarity. Fortunately, IDE's have become very helpful over the years :)
-Jeff On Thu, Dec 3, 2015 at 10:45 AM Michael B. Smith <[email protected]> wrote: > Get-Date is correct. > > > > I was thinking of the .NET version of the same command: [DateTime]::Now. > > > ------------------------------ > *From:* [email protected] <[email protected]> > on behalf of Jesse Rink <[email protected]> > *Sent:* Thursday, December 3, 2015 10:13 AM > > *To:* [email protected] > *Subject:* [NTSysADM] Re: Powershell/scripting > > Think I'm making some headway on this. I tried this. > > > $BackupStatus = Invoke-Command -Computername servername -ScriptBlock { > add-Pssnapin Windows.serverbackup -ErrorAction SilentlyContinue; > Get-WBSummary } > $LastDate = $BackupStatus.LastSuccessfulBackupTime > $CurrentDate = Get-Date > echo ($CurrentDate-$LastDate).Days > > > That results in an integer ... so maybe I can use that. Will check > further. > > > > > Jesse Rink > > Source One Technology, Inc. > > HP Partner > > 262 993 2231 > > > ------------------------------ > *From:* [email protected] <[email protected]> > on behalf of Jesse Rink <[email protected]> > *Sent:* Thursday, December 3, 2015 8:54 AM > *To:* [email protected] > *Subject:* [NTSysADM] Re: Powershell/scripting > > > Michael, > > Close, but it doesn't seem to work. > > > Get-Now doesn't seem to be a recognized command in powershell. But I > found Get-Date is... however, the scripts as follows doesn't quite work. > > > $BackupStatus = Invoke-Command -Computername servername -ScriptBlock { > add-Pssnapin Windows.serverbackup -ErrorAction SilentlyContinue; > Get-WBSummary } > $LastDate = $BackupStatus.LastSuccessfulBackupTime > echo $LastDate > $DeltaDays = (Get-Date - $LastDate) > $DeltaDays.TotalDays > echo $LastDate > > > It will output the $LastDate fine, but get's stuck after that with this > error. > > Get-Date : Cannot bind parameter 'Date'. Cannot convert value "-" to type > "System.DateTime". Error: "String was not recognized as a valid DateTime." > > > Thoughts? > > > > > > 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 > > > > >
