$timeinfo = "01-06-2017 12:34"
$template = "dd-MM-yyyy HH:mm"
[DateTime]::ParseExact($timeinfo, $template, $null)
results in:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." At line:3 char:1 + [DateTime]::ParseExact($timeinfo, $template, $null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException
I can't tell what is wrong here? Why is my string not a valid datetime when I specify in the template how it should read it?