private/_PSTSOrchestrator.ps1
Function _import() { [CmdletBinding()] param( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string] $inFile ) [string[]]$fileContent = Get-Content $inFile $content = [String]::Empty foreach ($line in $fileContent) { $content = $content + "`n" + $line } $yamlobj = $(_fromYAML $content) return $yamlobj } Function _getValue() { [CmdletBinding()] param( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][HashTable] $ref, [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][object] $value ) if ($ref.Count -eq 0) { return $value } if ($value -is [System.Collections.IDictionary]) { @($value.GetEnumerator()) | ` ? {$_.Value } | ` % { $value[$_.Key]= _getValue -ref $ref -value $_.Value } } $matches = [regex]::Matches($value, "\[@([a-zA-z0-9.\-_]*?)(?:=>([a-zA-z]*?))?\]") foreach ($match in $matches) { if (! $match.Success ) { continue } switch ($match.Groups.Count) { #if there is a match [@<obj>=>prop] 3 { $propValue = ($ref[$match.Groups[1].Value] | ` Select -ExpandProperty $match.Groups[2].Value) } #if there is a match [@<obj>] 2 { $propValue = $ref[$match.Groups[1].Value] } } if ($value -eq $match.Groups[0].Value) { $value = $propValue } else { $value = $value -replace "\$($match.Captures.Value)", $propValue } } return $value } |