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

 
Participant
1 year, 2 months ago.

  • Author
    Posts
  • #80429

    Participant
    Points: 22
    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")
    	{
    		$db.name
    		Write-Host "Diff "$timediff.totalhours
    		Write-Host "Full "$timefull.totalhours
    		$failed += $backups.database_name
    	}
    
  • #80447

    Participant
    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

      Participant
      Points: 22
      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.