Today I met a problem with the conversion of this type of string "8/3/2020 10:29:33 AM" which I need to convert to date format.
I try this type of command and get an error every time:
$PwdExpiracy = "8/3/2020 10:29:33 AM"
$date = [datetime]::ParseExact($PwdExpiracy,'MM/dd/yyyy HH:mm:ss tt',$null)
The error is :
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
Au caractère Ligne:1 : 1
+ $date = [datetime]::ParseExact($PwdExpiracy,'MM/dd/yyyy HH:mm:ss tt',$nu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Could you help me with this ? That would be very kind of you!