Skip to content

Test-NBDeprecatedParameter

Since

v4.5.0.0

SYNOPSIS

Checks if a deprecated parameter is being used and handles it appropriately.

SYNTAX

Test-NBDeprecatedParameter [-ParameterName] <String> [-DeprecatedInVersion] <String>
 [[-RemovedInVersion] <String>] [-BoundParameters] <Hashtable> [[-ReplacementMessage] <String>]
 [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

This helper function checks if a deprecated parameter is being used and: - Emits a warning if the current Netbox version is >= the deprecation version - Returns $true if the parameter should be excluded from the API request - Returns $false if the parameter should still be sent (older Netbox version)

This allows for graceful deprecation of parameters while maintaining backwards compatibility with older Netbox versions.

EXAMPLES

EXAMPLE 1

# In a function with deprecated Is_Staff parameter:
if (Test-NBDeprecatedParameter -ParameterName 'Is_Staff' -DeprecatedInVersion '4.5.0' -BoundParameters $PSBoundParameters) {
    $PSBoundParameters.Remove('Is_Staff') | Out-Null
}

EXAMPLE 2

# Deprecated but still functional until Netbox 5.0 - warn, but keep sending the value:
$null = Test-NBDeprecatedParameter -ParameterName 'Ports' -DeprecatedInVersion '4.7.0' `
    -RemovedInVersion '5.0' -BoundParameters $PSBoundParameters `
    -ReplacementMessage 'Use -Port_Mappings instead.'

PARAMETERS

-ParameterName

The name of the deprecated parameter.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DeprecatedInVersion

The Netbox version where this parameter was deprecated/removed.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RemovedInVersion

The Netbox version that will remove the field entirely. Supplying this switches the helper to warn-only mode: the caller is told the parameter is on its way out, but the function returns $false so the value is still sent. Use this while a deprecated field is deprecated-but-functional; omit it once the server ignores the field.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BoundParameters

The $PSBoundParameters from the calling function.

Type: Hashtable
Parameter Sets: (All)
Aliases:

Required: True
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ReplacementMessage

Optional message explaining what to use instead.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

[bool] - $true if parameter should be excluded, $false if it should be included

NOTES

AddedInVersion: v4.5.0.0 This function requires that Connect-NBAPI has been called and $script:NetboxConfig.ParsedVersion is set.

Common parameters

common request params