Skip to content

Remove-Context

SYNOPSIS

Removes a context from the context vault.

SYNTAX

Remove-Context [-ID] <String[]> [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This function removes a context (or multiple contexts) from the vault. It supports: - Supply one or more IDs as strings (e.g. -ID 'Ctx1','Ctx2') - Supply objects that contain an ID property

The function accepts pipeline input for easier batch removal.

EXAMPLES

EXAMPLE 1

Remove-Context -ID 'MySecret'

Output:

Removing context [MySecret]
Removed item: MySecret

Removes a context called 'MySecret' by specifying its ID.

EXAMPLE 2

Remove-Context -ID 'Ctx1','Ctx2'

Output:

Removing context [Ctx1]
Removed item: Ctx1
Removing context [Ctx2]
Removed item: Ctx2

Removes two contexts, 'Ctx1' and 'Ctx2'.

EXAMPLE 3

'Ctx1','Ctx2' | Remove-Context

Output:

Removing context [Ctx1]
Removed item: Ctx1
Removing context [Ctx2]
Removed item: Ctx2

Removes two contexts, 'Ctx1' and 'Ctx2' via pipeline input.

EXAMPLE 4

$ctxList = @(
    [PSCustomObject]@{ ID = 'Ctx1' },
    [PSCustomObject]@{ ID = 'Ctx2' }
)
$ctxList | Remove-Context

Output:

Removing context [Ctx1]
Removed item: Ctx1
Removing context [Ctx2]
Removed item: Ctx2

Accepts pipeline input: multiple objects each having an ID property.

PARAMETERS

-ID

One or more IDs as strings of the contexts to remove.

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

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

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

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

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

-Confirm

Prompts you for confirmation before running the cmdlet.

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

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

[System.String]

NOTES

Returns the name of each removed context if successful.

https://psmodule.io/Context/Functions/Remove-Context/