Add-AzureRmAccount
Adds an authenticated account to use for Azure Resource Manager cmdlet requests.
Note
The cmdlets referenced in this documentation are for managing legacy Azure resources that use Azure Service Manager (ASM) APIs. This legacy PowerShell module isn't recommended when creating new resources since ASM is scheduled for retirement. For more information, see Azure Service Manager retirement.
The Az PowerShell module is the recommended PowerShell module for managing Azure Resource Manager (ARM) resources with PowerShell.
Syntax
Add-AzureRmAccount
[-Environment <String>]
[[-Credential] <PSCredential>]
[-TenantId <String>]
[-SubscriptionId <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
[[-Credential] <PSCredential>]
[-TenantId <String>]
-SubscriptionName <String>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
[-Credential] <PSCredential>
[-ServicePrincipal]
-TenantId <String>
[-SubscriptionId <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
[-Credential] <PSCredential>
[-ServicePrincipal]
-TenantId <String>
-SubscriptionName <String>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
-CertificateThumbprint <String>
-ApplicationId <String>
[-ServicePrincipal]
-TenantId <String>
[-SubscriptionId <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
-CertificateThumbprint <String>
-ApplicationId <String>
[-ServicePrincipal]
-TenantId <String>
-SubscriptionName <String>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
[-TenantId <String>]
-AccessToken <String>
-AccountId <String>
[-SubscriptionId <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Add-AzureRmAccount
[-Environment <String>]
[-TenantId <String>]
-AccessToken <String>
-AccountId <String>
-SubscriptionName <String>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Add-AzureRmAcccount cmdlet adds an authenticated Azure account to use for Azure Resource Manager cmdlet requests.
You can use this authenticated account only with Azure Resource Manager cmdlets. To add an authenticated account for use with Service Management cmdlets, use the Add-AzureAccount or the Import-AzurePublishSettingsFile cmdlet.
Examples
Example 1: Add an account that requires interactive login
PS C:\>Add-AzureRmAccount
Account: azureuser@contoso.com
Environment: AzureCloud
Subscription: xxxx-xxxx-xxxx-xxxx
Tenant: xxxx-xxxx-xxxx-xxxx
This command adds an Azure Resource Manager account.
To run Azure Resource Manager cmdlets with this account, you must provide Microsoft account or organizational ID credentials at the prompt.
If multi-factor authentication is enabled for your credentials, you must log in using the interactive option or use service principal authentication.
Example 2: Add an account that authenticates with organizational ID credentials
PS C:\>$Credential = Get-Credential
PS C:\> Add-AzureRmAccount -Credential $Credential
Account: azureuser@contoso.com
Environment: AzureChinaCloud
Subscription: xxxx-xxxx-xxxx-xxxx
Tenant: xxxx-xxxx-xxxx-xxxx
The first command gets the user credentials, and then stores them in the $Credential variable.
The second command adds an Azure Resource Manager account with the credentials in $Credential.
This account authenticates with Azure Resource Manager using organizational ID credentials. You cannot use multi-factor authentication or Microsoft account credentials to run Azure Resource Manager cmdlets with this account.
Example 3: Add an account that authenticates with service principal credentials
PS C:\>$Credential = Get-Credential
PS C:\> Add-AzureRmAccount -Credential $Credential -Tenant "xxxx-xxxx-xxxx-xxxx" -ServicePrincipal
Account: xxxx-xxxx-xxxx-xxxx
Environment: AzureCloud
Subscription: yyyy-yyyy-yyyy-yyyy
Tenant: xxxx-xxxx-xxxx-xxxx
The first command gets the user credentials, and then stores them in the $Credential variable.
The second command adds an Azure Resource Manager account with the credentials stored in $Credential for the specified Tenant. The ServicePrincipal switch parameter indicates that the account authenticates as a service principal.
Example 4: Add an account for a specific tenant and subscription
PS C:\>Add-AzureRmAccount -Tenant "xxxx-xxxx-xxxx-xxxx" -SubscriptionId "yyyy-yyyy-yyyy-yyyy"
Account: pfuller@contoso.com
Environment: AzureCloud
Subscription: yyyy-yyyy-yyyy-yyyy
Tenant: xxxx-xxxx-xxxx-xxxx
This command adds an Azure Resource Manager account to run cmdlets for the specified tenant and subscription by default.
Parameters
-AccessToken
Specifies an access token.
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-AccountId
Account Id for access token
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ApplicationId
SPN
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-CertificateThumbprint
Certificate Hash (Thumbprint)
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Credential
Specifies a PSCredential object. For more information about the PSCredential object, type Get-Help Get-Credential.
The PSCredential object provides the user ID and password for organizational ID credentials, or the application ID and secret for service principal credentials.
Type: | PSCredential |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Environment
Environment containing the account to log into
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ServicePrincipal
Indicates that this account authenticates by providing service principal credentials.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-SubscriptionId
Specifies the ID of the subscription. If you do not specify this parameter, the first subscription from the subscription list is used.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-SubscriptionName
Subscription Name
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-TenantId
Optional tenant name or ID
Type: | String |
Aliases: | Domain |
Position: | Named |
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 run.
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Outputs
PSAzureProfile