If statment multiple conditions

Welcome Forums General PowerShell Q&A If statment multiple conditions

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 5 months ago.

  • Author
  • #80429

    Points: 42
    Rank: Member

    Hi I am trying to make a script to monitor my SQL backups. Everything works fine except that we are running differential backups 6 days a week and a full backup once a week. I want to check that latest full back or latest diff backup max 28 hours old. This is my if statement so far. Can anyone point me in right direction how to get it work properly?

    elseif (($recovery.recovery_model -eq 'SIMPLE') -and (($timediff.totalhours -lt "28") -or ($timefull.totalhours -lt "28")) -or $timefull.days -gt "7")
    		Write-Host "Diff "$timediff.totalhours
    		Write-Host "Full "$timefull.totalhours
    		$failed += $backups.database_name
  • #80447

    Points: 0
    Rank: Member

    so what the problem ?
    btw, you should use number values without quotes, it not strings

    $timediff.totalhours -lt 28

    you do not write, what contains in $timediff variable, it is difference between current time and time of backup or something another
    if so, you need something like

    ($full.totaldays -gt 7 -and $full.hours -gt 28) -or ($diff.totalhours -gt 28)
    • #80470

      Points: 42
      Rank: Member

      Thanks for your input. Changed my statment to your suggestion and got expected result back.

      ($full.totaldays -gt 7 -and $full.hours -gt 28) -or ($diff.totalhours -gt 28)

The topic ‘If statment multiple conditions’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort