Skip to content

Remove-HashtableEntry

SYNOPSIS

Removes specific entries from a hashtable based on given criteria.

SYNTAX

Remove-HashtableEntry [-Hashtable] <Hashtable> [-NullOrEmptyValues] [[-Types] <String[]>] [[-Keys] <String[]>]
 [-KeepNullOrEmptyValues] [[-KeepTypes] <String[]>] [[-KeepKeys] <String[]>] [-All]
 [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

This function filters out entries from a hashtable based on different conditions. You can remove keys with null or empty values, keys of a specific type, or keys matching certain names. It also allows keeping entries based on the opposite criteria. If the -All parameter is used, all entries in the hashtable will be removed.

EXAMPLES

EXAMPLE 1

$myHashtable = @{ Name = 'John'; Age = 30; Country = $null }
$myHashtable | Remove-HashtableEntry -NullOrEmptyValues

Output:

@{ Name = 'John'; Age = 30 }

Removes entries with null or empty values from the hashtable.

EXAMPLE 2

$myHashtable = @{ Name = 'John'; Age = 30; Active = $true }
$myHashtable | Remove-HashtableEntry -Types 'Boolean'

Output:

@{ Name = 'John'; Age = 30 }

Removes entries where the value type is Boolean.

EXAMPLE 3

$myHashtable = @{ Name = 'John'; Age = 30; Country = 'USA' }
$myHashtable | Remove-HashtableEntry -Keys 'Age'

Output:

@{ Name = 'John'; Country = 'USA' }

Removes the key 'Age' from the hashtable.

PARAMETERS

-Hashtable

The hashtable to remove entries from.

Type: Hashtable
Parameter Sets: (All)
Aliases:

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

-NullOrEmptyValues

Remove keys with null or empty values.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

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

-Types

Remove keys of a specified type.

Type: String[]
Parameter Sets: (All)
Aliases:

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

-Keys

Remove keys with a specified name.

Type: String[]
Parameter Sets: (All)
Aliases: Names

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

-KeepNullOrEmptyValues

Remove keys with null or empty values.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: IgnoreNullOrEmptyValues

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

-KeepTypes

Keep only keys of a specified type.

Type: String[]
Parameter Sets: (All)
Aliases: IgnoreTypes

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

-KeepKeys

Keep only keys with a specified name.

Type: String[]
Parameter Sets: (All)
Aliases: IgnoreKey, KeepNames

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

-All

Remove all entries from the hashtable.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
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

void

NOTES

The function modifies the input hashtable but does not return output.

https://psmodule.io/Hashtable/Functions/Remove-HashtableEntry/