I have a PowerShell script which reads a CSV file and filters out data as per my requirement, but the catch is that it ONLY works on my Windows 8.1 system and nowhere else.
-gt
is working as it should. The problem is that you're trying to compare string-values with -gt
. To compare dates, they need to be DateTime
-objects. When you import a CSV file, all values are imported as strings. You need to convert the date back to a DateTime
-object. Ex:
$date1=(get-date).AddDays(-1)
echo $date1
Import-Csv C:\avaya\2014.04.csv | Where-Object { $_.Party1Name -eq "User_Name" -and ($_.'Call Start' -as [datetime]) -gt $date1 } | Export-Csv -Path "result.csv" -NoTypeInformation