Read a Date from Text File and Compare with Current Date in Powershell
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...
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.
1 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"}