Private/Path/Get-ABPath.ps1
function Get-ABPath { [OutputType([string])] [CmdletBinding()] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [String] $Path, [Parameter(Mandatory = $false)] [Hashtable] $PathParameters ) begin { $Paths = Get-Content "$PSScriptRoot\Paths.json" | ConvertFrom-Json } process { # If there are any parameters given, then they are place in the returned string if ($PathParameters) { $ReturnValue = $Paths.psObject.Properties[$Path].value foreach ($key in $PathParameters.Keys) { $ReturnValue = $ReturnValue -replace "{{$key}}", $PathParameters[$key] } } else { $ReturnValue = $Paths.psObject.Properties[$Path].value } if ($ReturnValue -match "{{.+}}") { throw [System.NullReferenceException]::new("$($Matches[0]) not supplied!") } Return $ReturnValue } end { } } |