Sep 28 2023 02:04 PM
I have an unusual one. The AddDays method of Get-Date isn't returning a value on my computer. It's not working in PowerShell 5 or 7. Get-date by itself works find and returns today's date.
PS C:\Users\Me> get-date
Thursday, September 28, 2023 3:39:06 PM
PS C:\Users\Me> (get-date).AddDays.(-30)
PS C:\Users\Me>
Oddly, it works fine from an elevated window (using a separate admin account).
PS C:\Scripts> get-date
Thursday, September 28, 2023 3:41:36 PM
PS C:\Scripts> (get-date).AddDays(-30)
Tuesday, August 29, 2023 3:41:49 PM
PS C:\Scripts>
It seems like a profile issue, so I deleted my PS profile and created a new one, but it's the same thing.
Anyone seen something like this before?
Sep 28 2023 02:15 PM
Sep 28 2023 02:22 PM
Sep 28 2023 02:37 PM
Sep 28 2023 02:50 PM
Sep 28 2023 03:05 PM
Sep 28 2023 03:55 PM
Solution
In line six of your original post, you have made a small syntax mistake, which is why it returns nothing.
From line 6, this:
(get-date).AddDays.(-30)
Should have been this (note the removal of the period prior to the "(-30)"):
(get-date).AddDays(-30)
Cheers,
Lain
Sep 28 2023 06:37 PM
Sep 28 2023 03:55 PM
Solution
In line six of your original post, you have made a small syntax mistake, which is why it returns nothing.
From line 6, this:
(get-date).AddDays.(-30)
Should have been this (note the removal of the period prior to the "(-30)"):
(get-date).AddDays(-30)
Cheers,
Lain