I am recording the information from Get-Date to a text file because I am going to compare it against events that occur in the future. As well I do not want it to alert again within a specified time range.
My issue is as follows:
1. If you use Get-Date it adds in a line above it.
2. This is extremely annoying as when I do a Get-Date > C:\temp\CurrentTime.txt
3. Then do a [datetime] $RecordedTime = Get-content C:\temp\CurrentTime.txt
It then errors out telling me that it cannot convert it. Which is perfectly true as well a date and time of course cannot be blank.
Any suggestions on how I can use Get-date but not have the new line appear. And no Write-host Get-Date -NoNewLine does not work. 🙂
Thank you for your time.
by Klaas at 2012-10-30 03:04:29
That's because get-date returns an object, not a string. You can pass -format or -displayhint parameters or use a .tostring() method to pull the exact output you want.