Private/Merge-Path.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<#
.SYNOPSIS Combines several strings or paths to a single path. .DESCRIPTION Takes one or more strings as an array and merges them into a single path with the help of [System.IO.Path]::Combine(). Same result can be achieved with Join-Path in PS 6.0 and above, but this lets us be backwards compatible. .PARAMETER Path Array of paths/strings to merge. .EXAMPLE Combine an array of paths into a single path. Returns "C:\Windows\System32\etc\hosts" (on Windows). Merge-Path "C:\Windows", "System32", "etc", "hosts" .NOTES Written by Lars Åkerlund, Redeploy AB. #> function Merge-Path { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string[]] $Path ) process { [System.IO.Path]::Combine($Path) # The end } } |