I am newbie to powershell and trying to filter required values and need help here.
Scenario:
From csv file which has columns name, u_last_backup, I’m trying to filter only names which are dated other than $strdates 2018-10-17,2018-10-16,2018-10-15,2018-10-14
In this script, though u_last_backup value is in list of $strdates, still I see if loop is not executed and goes to else statement and indeed all host names come up though having latest backup.
This might be a bit messy, but the dates could be included in the if statement.
CSV:
u_last_backup Name
10/17/2018 Server A
10/16/2018 Server B
10/15/2018 Server C
10/14/2018 Server D
10/13/2018 Server F
10/12/2018 Server G
$Hosts = Import-Csv .\Hostswithnobackupdates.csv
Foreach ($Server in $Hosts) {
$ServerName = $Server.Name
$Date = $Server.u_last_backup
if ($Date.Contains("10/17/2018") -or ($Date.Contains("10/16/2018")) -or ($Date.Contains("10/15/2018") -or ($Date.Contains("10/14/2018")))) {
Write-Host "$ServerName Has the latest backups"
}
Else {
Write-Host "$ServerName Does not have the latest backups"
}
}
Returned Values:
Server A Has the latest backups
Server B Has the latest backups
Server C Has the latest backups
Server D Has the latest backups
Server F Does not have the latest backups
Server G Does not have the latest backups