internal/functions/Convert-ParametersToString.ps1
function Convert-ParametersToString { param ( [hashtable] $Parameters, [string] $OutputType ) [string] $text = "" [hashtable] $csvParametersHt = @{} if ($Parameters.psbase.Count -gt 0) { foreach ($parameterName in $Parameters.Keys) { $parameter = $Parameters.$parameterName $multiUse = $parameter.multiUse $isEffect = $parameter.isEffect $value = $parameter.value $defaultValue = $parameter.defaultValue $definition = $parameter.definition $policySetDisplayNames = $parameter.policySets if ($null -eq $value -and $null -eq $defaultValue) { $noDefault = $true $value = "++ no default ++" } elseif ($null -eq $value) { $value = $defaultValue } switch ($OutputType) { csvValues { if (-not ($multiUse -or $isEffect)) { $null = $csvParametersHt.Add($parameterName, $value) } } csvDefinitions { if (-not $multiUse) { $null = $csvParametersHt.Add($parameterName, $definition) } } jsonc { $parameterString = "`"$($parameterName)`": $(ConvertTo-Json $value -Depth 100 -Compress), // '$($policySetDisplayNames -Join "', '")'" if ($multiUse) { $text += "`n // Multi-use: ($parameterString)" } elseif ($noDefault) { $text += "`n // No-default: ($parameterString)" } else { $text += "`n $($parameterString)," } } Default { Write-Error "Convert-ParametersToString: unknown outputType '$OutputType'" -ErrorAction Stop } } } if (($OutputType -eq "csvValues" -or $OutputType -eq "csvDefinitions") -and $csvParametersHt.psbase.Count -gt 0) { $text = ConvertTo-Json $csvParametersHt -Depth 100 -Compress } } return $text } |