forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvertTo-FormattedParameterDescription.ps1
More file actions
85 lines (71 loc) · 2.25 KB
/
ConvertTo-FormattedParameterDescription.ps1
File metadata and controls
85 lines (71 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<#
.SYNOPSIS
Converts a hashtable of bound parameters into a formatted string for ShouldProcess descriptions.
.DESCRIPTION
This function takes a hashtable of bound parameters and formats them into a readable string
for use in ShouldProcess verbose descriptions. It excludes non-settable parameters and
formats each parameter as 'ParameterName: Value'.
.PARAMETER BoundParameters
Hashtable of bound parameters (typically $PSBoundParameters).
.PARAMETER Exclude
Array of parameter names to exclude from the formatted output.
.INPUTS
None.
.OUTPUTS
`System.String`
Returns a formatted string with parameters and their values.
.EXAMPLE
$formattedText = ConvertTo-FormattedParameterDescription -BoundParameters $PSBoundParameters -Exclude @('ServerObject', 'Name', 'Force')
Returns a formatted string like:
"
EmailAddress: 'admin@company.com'
CategoryName: 'Notifications'
"
#>
function ConvertTo-FormattedParameterDescription
{
[CmdletBinding()]
[OutputType([System.String])]
param
(
[Parameter(Mandatory = $true)]
[System.Collections.Hashtable]
$BoundParameters,
[Parameter()]
[System.String[]]
$Exclude = @()
)
$parameterDescriptions = @()
foreach ($parameter in ($BoundParameters.Keys | Sort-Object))
{
if ($parameter -notin $Exclude)
{
$raw = $BoundParameters[$parameter]
$value = if ($raw -is [System.Security.SecureString])
{
'***'
}
elseif ($raw -is [System.Management.Automation.PSCredential])
{
$raw.UserName
}
elseif ($raw -is [System.Array])
{
($raw -join ', ')
}
else
{
$raw
}
$parameterDescriptions += "$parameter`: '$value'"
}
}
if ($parameterDescriptions.Count -gt 0)
{
return "`r`n " + ($parameterDescriptions -join "`r`n ")
}
else
{
return " $($script:localizedData.ConvertTo_FormattedParameterDescription_NoParametersToUpdate)"
}
}