When using PowerShell, why can I not use the overloaded ToString() methods for the TimeSpan structure?
$ts = New-TimeSpan -Days 5
$ts.ToString("g")
Cannot find an overload for "ToString" and the argument count: "1".
At line:1 char:13
+ $ts.ToString <<<< ("g")
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
Is there a workaround?
I think what is going on is that you want the .NET 4 version of TimeSpan.ToString(), which has 2 overloads, and you are getting the .NET 3.5 version of TimeSpan.ToString(), which does not have any overloads. If you look at this question on StackOverflow it shows how to get PS to use the .NET 4 assemblies.
[Addition] After creating the config file per the link above, I was able to get the following to execute successfully: