Disconnect-AzAccount

Disconnects a connected Azure account and removes all credentials and contexts associated with that account.

Syntax

Disconnect-AzAccount
          [-ContextName <String>]
          [-Scope <ContextModificationScope>]
          [-DefaultProfile <IAzureContextContainer>]
          [-WhatIf]
          [-Confirm]
          [<CommonParameters>]
Disconnect-AzAccount
          [-Username] <String>
          [-Scope <ContextModificationScope>]
          [-DefaultProfile <IAzureContextContainer>]
          [-WhatIf]
          [-Confirm]
          [<CommonParameters>]
Disconnect-AzAccount
          -ApplicationId <String>
          -TenantId <String>
          [-Scope <ContextModificationScope>]
          [-DefaultProfile <IAzureContextContainer>]
          [-WhatIf]
          [-Confirm]
          [<CommonParameters>]
Disconnect-AzAccount
          [-InputObject] <PSAzureRmAccount>
          [-Scope <ContextModificationScope>]
          [-DefaultProfile <IAzureContextContainer>]
          [-WhatIf]
          [-Confirm]
          [<CommonParameters>]
Disconnect-AzAccount
          [-AzureContext] <PSAzureContext>
          [-Scope <ContextModificationScope>]
          [-DefaultProfile <IAzureContextContainer>]
          [-WhatIf]
          [-Confirm]
          [<CommonParameters>]

Description

The Disconnect-AzAccount cmdlet disconnects a connected Azure account and removes all credentials and contexts (subscription and tenant information) associated with that account. After executing this cmdlet, you will need to login again using Connect-AzAccount.

Examples

Example 1: Logout of the current account

Disconnect-AzAccount

Logs out of the Azure account associated with the current context.

Example 2: Logout of the account associated with a particular context

Get-AzContext "Work" | Disconnect-AzAccount -Scope CurrentUser

Logs out the account associated with the given context (named 'Work'). Because this uses the 'CurrentUser' scope, all credentials and contexts will be permanently deleted.

Example 3: Log out a particular user

Disconnect-AzAccount -Username 'user1@contoso.org'

Logs out the 'user1@contoso.org' user - all credentials and all contexts associated with this user will be removed.

Parameters

-ApplicationId

ServicePrincipal id (globally unique id)

Type:String
Aliases:SPN, ServicePrincipal
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-AzureContext

Context

Type:PSAzureContext
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ContextName

Name of the context to log out of

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

-DefaultProfile

The credentials, tenant and subscription used for communication with azure

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

The account object to remove

Type:PSAzureRmAccount
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Scope

Determines the scope of context changes, for example, whether changes apply only to the current process, or to all sessions started by this user.

Type:ContextModificationScope
Accepted values:Process, CurrentUser
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-TenantId

Tenant id (globally unique id)

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

-Username

User name of the form 'user@contoso.org'

Type:String
Aliases:Id, UserId
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

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

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PSAzureRmAccount

PSAzureContext

Outputs

PSAzureRmAccount