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.

4

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"} 
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.