Private/Module/Get-ASTScriptParameters.ps1
function Get-ASTScriptParameters { <# .Description Get-ASTScriptParameters is used by New-VirtualMachine.ps1 to dynamically enumerate it's input paramters and YAML Node Template Configuration configuration stored as JSON. The JSON metadata stored is the _YAMLPath (Generated by Format-YAMLObject) associating the parameter to the corrosponding Node Template Configuration. The JSON is formatted as follows: @{ Name = # Enumerated Script Parameter Name LookupValue = #_YAMLPath object structure (Generated by Format-YAMLObject) } (See ConvertTo-PowerShellParameter) Using this information, PowerShell can then associate the parameters enumerated with the corrosponding JSON metadata. Why? New-VirtualMachine is dynamically generated script with changing paramters based on the Datum Module, Resolution Precidence and node configuration. To address this, Get-ASTScriptParamters loads and associates those paramters to the correct Node Template Configuration items. .PARAMETER ScriptPath FilePath of the PowerShell Script to load. .EXAMPLE $ScriptParameterData = Get-ASTScriptParameters -ScriptPath $MyInvocation.MyCommand.Path .SYNOPSIS Returns a list of paramters and optional JSON data in an object for a given PowerShell Script. #> param( # Parameter help description [Parameter(Mandatory)] [String] $ScriptPath ) $ErrorActionPreference = 'Stop' [PSCustomObject]@{ Parameters = (Get-Command $ScriptPath).ScriptBlock.Ast.ParamBlock.Parameters.Name.Extent.Text YAMLData = Get-Content $ScriptPath | Where-Object {$_ -like '*#JSONData:*'} | ForEach-Object { if (-not($_ -match '\#(JSONData:?)(?<json>.+)')) { return } $Matches['json'] | ConvertFrom-Json } } } if ($isModule) { Export-ModuleMember -Function Get-ASTScriptParameters } |