Files
Merge-DSCConfigurationData/Private/ConvertTo-ConfigurationDataRelativePath.ps1

30 lines
973 B
PowerShell

function ConvertTo-ConfigurationDataRelativePath {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]
$Path,
[Parameter(Mandatory=$true)]
[string]
$BasePath
)
$ResolvedPath = Repair-ConfigurationDataPathEncoding -Path $Path
$ResolvedBasePath = Repair-ConfigurationDataPathEncoding -Path $BasePath
try {
$PathUri = [System.Uri]::new((Resolve-Path -LiteralPath $ResolvedPath).ProviderPath)
$BaseUriPath = [System.IO.Path]::GetFullPath($ResolvedBasePath)
if(-not $BaseUriPath.EndsWith([System.IO.Path]::DirectorySeparatorChar)){
$BaseUriPath += [System.IO.Path]::DirectorySeparatorChar
}
$BaseUri = [System.Uri]::new($BaseUriPath)
return [System.Uri]::UnescapeDataString($BaseUri.MakeRelativeUri($PathUri).ToString()).Replace('/', [System.IO.Path]::DirectorySeparatorChar)
}
catch {
return $ResolvedPath
}
}