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

Logout of the current account

PS C:\> Disconnect-AzAccount

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

Logout of the account associated with a particular context

PS C:\> 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.

Log out a particular user

PS C:\> 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
Accept pipeline input:False
Accept wildcard characters:False
-AzureContext

Context

Type:Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext
Position:0
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Confirm

Prompts you for confirmation before running the cmdlet.

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

Name of the context to log out of

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

The credentials, tenant and subscription used for communication with azure

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-InputObject

The account object to remove

Type:Microsoft.Azure.Commands.Profile.Models.PSAzureRmAccount
Position:0
Default value:None
Accept pipeline input:True (ByValue)
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
Accept pipeline input:False
Accept wildcard characters:False
-TenantId

Tenant id (globally unique id)

Type:String
Position:Named
Default value:None
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
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
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.Azure.Commands.Profile.Models.PSAzureRmAccount

Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext

Outputs

Microsoft.Azure.Commands.Profile.Models.PSAzureRmAccount