-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path2025-04-18-capture-superfluous-parameters-passed-to-your-functions.ps1
More file actions
21 lines (19 loc) · 1.4 KB
/
2025-04-18-capture-superfluous-parameters-passed-to-your-functions.ps1
File metadata and controls
21 lines (19 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$tip = [tiPS.PowerShellTip]::new()
$tip.CreatedDate = [DateTime]::Parse('2025-04-18')
$tip.Title = 'Capture superfluous parameters passed to your function(s)'
$tip.TipText = @'
Capture any parsed parameter to prevent a function from bombing out when being passed unknown / misspelled variables.
Comes in handy when parsing the $PSBoundParameters from a calling script with just a subset of parameters that are appropriate / needed by your (custom) function.
'@
$tip.Example = @'
[CmdletBinding()]
param(
[Parameter(DontShow, ValueFromRemainingArguments)]$Superfluous
)
Write-Verbose -Message "Ignoring superfluous params: $($Superfluous -join ' ')"
'@
$tip.Urls = @('https://github.com/ChristelVDH/SyncAD2AAD/blob/main/ConnectTo-Graph.ps1','https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.parameterattribute.valuefromremainingarguments','https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.parameterattribute.dontshow')
$tip.Category = [tiPS.TipCategory]::Syntax # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other.
$tip.Author = 'Christel VdH' # Optional. Get credit for your tip. e.g. 'Daniel Schroeder (deadlydog)'.
#$tip.ExpiryDate = [DateTime]::Parse('2024-10-30') # Optional. If the tip is not relevant after a certain date, set the expiration date. e.g. Announcing a conference or event.
# Tip submitted via GitHub issue workflow.