How do I use Join-Path to combine more than two strings into a file path?

Solution 1:

You can use the .NET Path class:

[IO.Path]::Combine('C:\', 'Foo', 'Bar')

Solution 2:

Since Join-Path can be piped a path value, you can pipe multiple Join-Path statements together:

Join-Path "C:" -ChildPath "Windows" | Join-Path -ChildPath "system32" | Join-Path -ChildPath "drivers"

It's not as terse as you would probably like it to be, but it's fully PowerShell and is relatively easy to read.