forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-CommandParameter.ps1
More file actions
55 lines (41 loc) · 1.68 KB
/
Get-CommandParameter.ps1
File metadata and controls
55 lines (41 loc) · 1.68 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
<#
.SYNOPSIS
Gets command parameters excluding specified ones.
.DESCRIPTION
This private function filters command parameters by excluding specified parameter names,
common parameters, and optional common parameters. It returns an array of parameter names
that can be used to set properties on objects.
.PARAMETER Command
Specifies the command information object containing parameter definitions.
.PARAMETER Exclude
Specifies an optional array of parameter names to exclude from the result.
Common parameters and optional common parameters are always excluded.
.INPUTS
None.
.OUTPUTS
`System.String[]`
Returns an array of parameter names that are not excluded.
.EXAMPLE
$settableProperties = Get-CommandParameter -Command $MyInvocation.MyCommand -Exclude @('ServerObject', 'Name', 'PassThru', 'Force')
Returns all parameters except the excluded ones and common parameters.
.EXAMPLE
$settableProperties = Get-CommandParameter -Command $MyInvocation.MyCommand
Returns all parameters except common parameters and optional common parameters.
#>
function Get-CommandParameter
{
[CmdletBinding()]
[OutputType([System.String[]])]
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.FunctionInfo]
$Command,
[Parameter()]
[System.String[]]
$Exclude = @()
)
$parametersWithoutCommon = Remove-CommonParameter -Hashtable $Command.Parameters
$settableProperties = $parametersWithoutCommon.Keys | Where-Object -FilterScript { $_ -notin $Exclude }
return $settableProperties
}