I am writing a script to get the results based on the user input, here user can give in date or date time... i need to get the results based on the input (date or datetime).
I have tried like below:
$StartDate = Read-Host -Prompt 'Enter the start date of the logs, Ex: 17/07/2017 or 17/07/2017 09:00:00'
$culture = [Globalization.CultureInfo]::InvariantCulture
$pattern = 'dd\/MM\/yyyy HH:mm:ss', 'dd\/MM\/yyyy'
$params['After'] = [DateTime]::ParseExact($StartDate, $pattern, $culture)
getting the below error:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
+ $params['After'] = [DateTime]::ParseExact <<<< ($StartDate, $pattern, $culture)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Please suggest, am i missing anything here.