Forum Discussion
Task scheduler messes up date format in my PowerShell script
- Jan 08, 2021
As I see it, its a Culture issue
which account is used to run the script, let me tell you this
Actually, your script is throwing an Exception, which is String was not recognized as a valid DateTime
But it was not displayed and totally ignored due to $ErrorActionPreference.
As a quick fix you will need to configure the account which is used to Run the script as with the same System TimeDate configuration or try to load the culture
https://stackoverflow.com/questions/44654045/get-date-formatting-culture
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.parseexact?view=net-5.0
The reason why the $Result is in minus when running it using the scheduler is $ExpDateToDT is Null
Hope this helps.
---------------------
If this Answer help, please click on Best Response and give like
As I see it, its a Culture issue
which account is used to run the script, let me tell you this
Actually, your script is throwing an Exception, which is String was not recognized as a valid DateTime
But it was not displayed and totally ignored due to $ErrorActionPreference.
As a quick fix you will need to configure the account which is used to Run the script as with the same System TimeDate configuration or try to load the culture
https://stackoverflow.com/questions/44654045/get-date-formatting-culture
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.parseexact?view=net-5.0
The reason why the $Result is in minus when running it using the scheduler is $ExpDateToDT is Null
Hope this helps.
---------------------
If this Answer help, please click on Best Response and give like
Thank you very much for your solution and sorry for the late response. I followed the quick fix you recommended and worked smoothly.
Best regards,
Alexandros