How to log in to Azure service principal
C

4

3
  1. Connect-AzureRMAccount doesn't work. I don't care. I don't want to run through the process of needing a PhD to understand why PowerShell never wants to work. So I'm going to use Login-AzureRMAccount

  2. I've followed the docs. Of course it's inadequate so here I am. https://learn.microsoft.com/en-us/powershell/azure/authenticate-azureps?view=azurermps-6.6.0

"In order to get the service principal's credentials as the appropriate object, use the Get-Credential cmdlet. This cmdlet will display a dialog box to enter the service principal user ID and password into."

Where do I even find my userID? I followed another docs instructions on creating an SP and all I did was create an app. I got the SP object in PowerShell, all it did was give me a NAME of the SP .

Now that I understand what User ID is. HOW do I log in? I use Login-AzureRmAccount AND Add-AzureRMAccount and they BOTH say

$p = Get-Credential
Add-AzureRmAccount -ServicePrincipal -ApplicationId "XXXXXXXXXX" -Credential $p -TenantId "XXXXXXXXXXX"
Add(/Login)-AzureRmAccount : Parameter set cannot be resolved using the specified named parameters.
Chlamydeous answered 7/8, 2018 at 5:38 Comment(0)
S
9

Try the command below to log in as a service principal,it works fine on my side.

$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 

enter image description here

For more details, refer to this similar issue.

Smarmy answered 7/8, 2018 at 7:32 Comment(6)
what's my password? I never created a password to my appChlamydeous
@meowtho The password is the key in the article, you could refer to it and create the key in the portal.Smarmy
IT WORKED. BLESS YOUR SOUL THANKSChlamydeous
Had issus with Add-AzureRmAccount. Connect-AzAccount seems to do the thingsLinton
In the output, did you got the subscription name? for me subscription is not coming, due to this, I am unable to access resources.Gunar
@Gunar You can set the subscription while you login using the switch : Connect-AzAccount -Credential $Credential -Tenant 'xxxx' -ServicePrincipal -Subscription 'xxxx'Frequentation
S
0

The what you call userId is the Application Id (Also known as ClientID) of your service principal.

Sherrillsherrington answered 7/8, 2018 at 5:40 Comment(0)
R
0

The following really should work for you

$pscredential = Get-Credential
Connect-AzureRmAccount -ServicePrincipal -ApplicationId  "http://my-app" -Credential $pscredential -TenantId $tenantid

Source: Microsoft Docs

Repartee answered 7/8, 2018 at 6:33 Comment(2)
*hi. I already said I'm not using Connect-AzureRmAccount. Doesn't work. Login-AzureRmAccount is an alias so it should work the sameChlamydeous
This worked for me $pscredential = Get-Credential Add-AzureRmAccount -Credential $pscredential -TenantId "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" -ServicePrincipalRepartee
F
0

Here is how you can use Az Powershell to login:

# Enter Service Principal's Object ID and Secret when prompted 
$Credential = Get-Credential

# Tenant ID
$TenantId = "XXX"
# Subscription ID
$SubscriptionId = "XXX"
Connect-AzAccount -Credential $Credential -Tenant $TenantId -ServicePrincipal -SubscriptionId $SubscriptionId
Frequentation answered 30/8, 2023 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.