-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvert-ArrayToPath.ps1
More file actions
45 lines (35 loc) · 936 Bytes
/
Convert-ArrayToPath.ps1
File metadata and controls
45 lines (35 loc) · 936 Bytes
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
38
39
40
41
42
43
44
45
function Convert-ArrayToPath {
<#
.SYNOPSIS
Join-Path for three or more strings.
.DESCRIPTION
Creates a path string joining all items with the path separator.
.EXAMPLE
@('c:\','temp','temp.txt') | Convert-ArrayToPath
#>
[CmdletBinding()]
param (
[Parameter(
ValueFromPipeline,
Position=0
)]
[validatenotnull()]
[string[]]
$Array
)
begin {
[string]$cmdString = "[IO.Path]::Combine({0})"
[string]$arrParams = ''
}
process {
foreach ($string in $Array) {
if ([string]::IsNullOrWhiteSpace($arrParams)) {} else {
$arrParams += ', '
}
$arrParams += "'$($string)'"
}
}
end {
Invoke-Expression ($cmdString -f $arrParams)
}
}#END: function Convert-ArrayToPath {}