I pipelined date to a text file through Powershell. Now i need to compare the date in the text file with the current date. I am unable to figure it out. Pls help.
(get-date).AddDays(3) | Out-File -FilePath c:\time.txt
$deadline = Get-Content -Path C:\time.txt
$currenttime = Get-Date
IF ($currenttime -lt $deadline)
{Write-host "Continue Working"}
Else
{Write-Host "Your Logic is Wrong"}I do not get any output. Pls help.
41 Answer
You should compare date with date.
(get-date).AddDays(3).ToString() | Out-File -FilePath time.txt
$deadline = [datetime](Get-Content -Path time.txt)
$currenttime = Get-Date
IF ($currenttime -lt $deadline) {Write-host "Continue Working"} Else {Write-Host "Your Logic is Wrong"} 0