< Back
Test-PSFParameterBinding
Post
NAME Test-PSFParameterBinding
SYNOPSIS
Helper function that tests, whether a parameter was bound.
SYNTAX
Test-PSFParameterBinding [-ParameterName] <String[]> [-Not] [-And] [-Mode <String>] [-BoundParameters <Object>]
[<CommonParameters>]
DESCRIPTION
Helper function that tests, whether a parameter was bound.
PARAMETERS
-ParameterName <String[]>
The name(s) of the parameter that is tested for being bound.
By default, the check is true when AT LEAST one was bound.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Not [<SwitchParameter>]
Reverses the result. Returns true if NOT bound and false if bound.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-And [<SwitchParameter>]
All specified parameters must be present, rather than at least one of them.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Mode <String>
Parameters can be explicitly bound or as scriptblocks to be invoked for each item piped to the command.
The mode determines, which will be tested for.
Supported Modes: Any, Explicit, PipeScript.
By default, any will do.
Whether a parameter was bound as PipeScript is only detectable during the begin block.
Required? false
Position? named
Default value Any
Accept pipeline input? false
Accept wildcard characters? false
-BoundParameters <Object>
The hashtable of bound parameters. Is automatically inherited from the calling function via default value.
Needs not be bound explicitly.
Required? false
Position? named
Default value (Get-PSCallStack)[0].InvocationInfo.BoundParameters
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>if (Test-PSFParameterBinding "Day")
{
}
Snippet as part of a function. Will check whether the parameter "Day" was bound. If yes, whatever logic is in the
conditional will be executed.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Test-PSFParameterBinding -Not 'Login', 'Spid', 'ExcludeSpid', 'Host', 'Program', 'Database'
Returns whether none of the parameters above were specified.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Test-PSFParameterBinding -And 'Login', 'Spid', 'ExcludeSpid', 'Host', 'Program', 'Database'
Returns whether any of the specified parameters was not bound
RELATED LINKS
SYNOPSIS
Helper function that tests, whether a parameter was bound.
SYNTAX
Test-PSFParameterBinding [-ParameterName] <String[]> [-Not] [-And] [-Mode <String>] [-BoundParameters <Object>]
[<CommonParameters>]
DESCRIPTION
Helper function that tests, whether a parameter was bound.
PARAMETERS
-ParameterName <String[]>
The name(s) of the parameter that is tested for being bound.
By default, the check is true when AT LEAST one was bound.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Not [<SwitchParameter>]
Reverses the result. Returns true if NOT bound and false if bound.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-And [<SwitchParameter>]
All specified parameters must be present, rather than at least one of them.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Mode <String>
Parameters can be explicitly bound or as scriptblocks to be invoked for each item piped to the command.
The mode determines, which will be tested for.
Supported Modes: Any, Explicit, PipeScript.
By default, any will do.
Whether a parameter was bound as PipeScript is only detectable during the begin block.
Required? false
Position? named
Default value Any
Accept pipeline input? false
Accept wildcard characters? false
-BoundParameters <Object>
The hashtable of bound parameters. Is automatically inherited from the calling function via default value.
Needs not be bound explicitly.
Required? false
Position? named
Default value (Get-PSCallStack)[0].InvocationInfo.BoundParameters
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>if (Test-PSFParameterBinding "Day")
{
}
Snippet as part of a function. Will check whether the parameter "Day" was bound. If yes, whatever logic is in the
conditional will be executed.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Test-PSFParameterBinding -Not 'Login', 'Spid', 'ExcludeSpid', 'Host', 'Program', 'Database'
Returns whether none of the parameters above were specified.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Test-PSFParameterBinding -And 'Login', 'Spid', 'ExcludeSpid', 'Host', 'Program', 'Database'
Returns whether any of the specified parameters was not bound
RELATED LINKS