Removes a subscription context from the current Azure PowerShell session.
Removes a subscription context from the current Azure PowerShell session.
Remove-AzContext [-Name] <String> [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-AzContext [-Context] <PSAzureContext> [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
The Remove-AzContext cmdlet removes a subscription context from the current Azure PowerShell session.
An Azure PowerShell context contains information about the current user, subscription, and default Azure environment.
This cmdlet is useful for cleaning up your session when you have multiple contexts loaded and want to remove one that is no longer needed.
| Name | Description | Required? | 
|---|---|---|
| -Name | Specifies the name of the context to remove. You can obtain context names by using Get-AzContext. | True (unless -Context is used) | 
| -Context | Specifies the context object to remove. You can obtain a context object by using Get-AzContext. | True (unless -Name is used) | 
| -Force | Suppresses confirmation prompts for removing the context. | False | 
| -PassThru | Returns the context object that the cmdlet removed. By default, this cmdlet does not output any objects. | False | 
| -WhatIf | Shows what would happen if the cmdlet runs. The cmdlet is not run. | False | 
| -Confirm | Prompts you for confirmation before running the cmdlet. | False | 
Remove-AzContext -Name "MyDevelopmentSubscription"
This command removes the Azure context named "MyDevelopmentSubscription" from the current session.
Get-AzContext | Remove-AzContext
This command gets the current Azure context and pipes it to Remove-AzContext to remove it.
Remove-AzContext -Name "OldSubscription" -PassThru
This command removes the context named "OldSubscription" and returns the context object to the pipeline.
Remove-AzContext -Name "TemporaryContext" -Force
This command removes the context named "TemporaryContext" without prompting for confirmation.
Microsoft.Azure.Commands.Common.Models.PSAzureContext
You can pipe a context object to this cmdlet.
Microsoft.Azure.Commands.Common.Models.PSAzureContext
When the -PassThru parameter is used, this cmdlet returns the context object that was removed.
Get-AzContext to view the contexts available in your session.