Files
Merge-DSCConfigurationData/Private/Resolve-ConfigurationDataTemplatePath.ps1

44 lines
1.2 KiB
PowerShell

function Resolve-ConfigurationDataTemplatePath {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]
$Path,
[Parameter(Mandatory=$false)]
[string]
$BasePath = (Get-Location).Path
)
$CandidatePaths = @()
foreach($CurrentPath in @($Path, (Repair-ConfigurationDataPathEncoding -Path $Path))){
if([string]::IsNullOrWhiteSpace($CurrentPath)){
continue
}
$CandidatePath = $CurrentPath
$CandidateBasePath = Repair-ConfigurationDataPathEncoding -Path $BasePath
if(-not [System.IO.Path]::IsPathRooted($CandidatePath)){
$CandidatePath = Join-Path -Path $CandidateBasePath -ChildPath $CandidatePath
}
if($CandidatePaths -notcontains $CandidatePath){
$CandidatePaths += $CandidatePath
}
}
$ResolvedPath = $null
foreach($CandidatePath in $CandidatePaths){
$ResolvedPath = Resolve-Path -LiteralPath $CandidatePath -ErrorAction SilentlyContinue
if($null -ne $ResolvedPath){
break
}
}
if($null -eq $ResolvedPath){
throw "Configuration data template [$Path] was not found. Base path [$BasePath]."
}
return $ResolvedPath.ProviderPath
}