< Back

Add-AzureAccount

Wed Jan 30, 2019 5:42 pm

NAME Add-AzureAccount



SYNOPSIS

Adds the Azure account to Windows PowerShell





SYNTAX

Add-AzureAccount [-Credential <PSCredential>] [-Environment <String>] [-SubscriptionDataFile <String>] [<CommonParameters>]





DESCRIPTION

The Add-AzureAccount cmdlet makes your Azure account and its subscriptions available in Windows PowerShell. It's like logging into your Azure account in

Windows PowerShell. To log out of the account, use the Remove-AzureAccount cmdlet.



Add-AzureAccount downloads information about your Azure account and saves it in a subscription data file in your roaming user profile. It also gets an

access token that allows Windows PowerShell to access your Azure account on your behalf. When the command completes, you can manage your Azure account

in Windows PowerShell.



There are two different ways to make your Azure account available to Windows PowerShell. You can use the Add-AzureAccount cmdlet, which uses Azure

Active Directory (Azure AD) authentication access tokens, or Import-AzurePublishSettingsFile, which uses a management certificate. For guidance on which

method to use, see "How to: Connect to your subscription"

(http://azure.microsoft.com/en-us/docume ... l/#Connect).



When you run Add-AzureAccount, it displays an interactive window that prompts you to sign into your Azure account. This sign-in is valid until the

access token expires. When it expires, cmdlets that require access to your account prompt you to run Add-AzureAccount again.



If you have a Microsoft Organizational account, you can use the -Credential parameter to add the subscriptions associated with your account to Windows

PowerShell without an interactive dialog.



This topic describes the cmdlet in the .7.2 version of the Microsoft Azure PowerShell module. To find out the version of the module you're using, from

the Azure PowerShell console, type (get-module azure).version.





PARAMETERS

-Credential <PSCredential>

The username and password account credentials used to authenticate with Azure Active Directory. The credentials must be for a Microsoft

Organizational account and not another kind of Microsoft account.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Environment <String>

Specifies an Azure environment for the user account. This parameter is optional. The default is the AzureCloud environment.



An Azure environment an independent deployment of Microsoft Azure, such as AzureCloud for global Azure and AzureChinaCloud for Azure operated by

21Vianet in China. You can also create on-premises Azure environments by using Azure Pack and the WAPack cmdlets. For more information, see Azure

Pack.



To get the available Azure environments, use the Get-AzureEnvironment cmdlet. To add an environment, use the Add-AzureEnvironment cmdlet.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-SubscriptionDataFile <String>

Specifies an alternate location for the subscription data file. This parameter is optional. By default, the subscription data file is saved in your

roaming user profile.



If you use this parameter to specify an alternate location for the subscription data file, be sure to use the SubscriptionDataFile parameters of

cmdlets that access your account. Otherwise, the cmdlets look for your account data in the default location.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

None



You cannot pipe input to this cmdlet





OUTPUTS

None



This cmdlet does not return any output.





NOTES





Add-AzureAccount (and the Azure AD authentication method) takes precedence over Import-AzurePublishSettings (and the management certificate method).

If you use Add-AzureAccount even once on your account, the Azure AD authentication method is used and the management certificate is ignored. To

remove the Azure AD token and restore the management certificate method, use the Remove-AzureAccount cmdlet. For more information, type: Get-Help

Remove-AzureAccount.



Keywords: azure, azuresm, servicemanagement, management, service, utilities

The error, "Your credentials have expired. Please use Add-AzureAccount to log in again." indicates that your access token is expired and Windows

PowerShell cannot access your Azure account. To restore access to your account, run Add-AzureAccount again.

The Azure PowerShell account and subscription cmdlets get their data from the subscription data file, not from the live Azure account. If you

change your account or subscriptions outside of Windows PowerShell, such as by using the Azure Management Portal, run Add-AzureAccount again to

refresh the subscription data file.



---------- Example 1: Add an account ----------



PS C:\\>Add-AzureAccount



This command adds an Azure account to Windows PowerShell. When you run the command, a windows pops up to request the user name and password of the

account.

---------- Example 2: Use an alternate subscription data file ----------



PS C:\\>Add-AzureAccount -SubscriptionDataFile C:\\Testing\\SDF.xml



This command uses the SubscriptionDataFile parameter to direct Add-AzureAccount to store the account data in the C:\\Testing\\SDF.xml file, instead of the

default file.

---------- Example 3: Add a Microsoft Organizational account using -Credential ----------



PS C:\\>$credential = Get-Credential

PS C:\\>Add-AzureAccount -Credential $credential



This command uses the Credential parameter to provide AAD authentication information on the command line, rather than using the pop-up dialog for AAD

authentication.

---------- Example 4: Add an account in Azure China ----------



PS C:\\>Add-AzureAccount -Environment AzureChinaCloud



This command uses the Environment parameter to add an Azure China account to Windows PowerShell. When you run the command, a windows pops up to request

the user name and password of the account.



RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkID=397618

Add-AzureEnvironment

Get-AzureEnvironment

Import-AzurePublishSettingsFile

Get-AzureAccount

Remove-AzureAccount