Below is a transcript of what I tried and what happens.
I am looking for how to cause a specific overload, along with an explanation of why the following does not work. If your answer is “you should use this command character instead” or “call it twice”, please understand when I do not accept your answer.
PS C:\> [System.IO.Path]::Combine("C:\", "foo") C:\foo PS C:\> [System.IO.Path]::Combine("C:\", "foo", "bar") Cannot find an overload for "Combine" and the argument count: "3". At line:1 char:26 + [System.IO.Path]::Combine <<<< ("C:\", "foo", "bar") + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest PS C:\> [System.IO.Path]::Combine(, "C:\", "foo", "bar") Missing ')' in method call. At line:1 char:27 + [System.IO.Path]::Combine( <<<< , "C:\", "foo", "bar") + CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Paren tContainsErrorRecordException + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall PS C:\> [System.IO.Path]::Combine($("C:\", "foo", "bar")) Cannot find an overload for "Combine" and the argument count: "1". At line:1 char:26 + [System.IO.Path]::Combine <<<< ($("C:\", "foo", "bar")) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest
this is what i do in c # that works:
var foobar = Path.Combine(@"C:\", "foo", "bar"); Console.WriteLine(foobar);
What will Powershell cause this particular overload? Path.Combine has both of these options:
public static string Combine (string path1, string path2, string path3); public static string Combine (params string[] paths);
Is it possible to call both of them or only one? Obviously, in this particular case it is difficult to tell the difference.