I'm trying to convert "PT5H" to ticks format using powershell. But facing below error:
System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'SuppressionDuration'. Cannot convert value "PT5H" to type "System.TimeSpan". Error: "String was not recognized as a valid TimeSpan."
Can anyone help me out in converting "PT5H"(String) to ticks ?
CodePudding user response:
You can use the XmlConvert.ToTimeSpan()
method to parse ISO8601 duration strings:
$duration = [System.Xml.XmlConvert]::ToTimeSpan('PT5H')
Command-Name -SuppressionDuration $duration