问题
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 useLogin-AzureRMAccount
I've followed the docs. Of course it's inadequate so here I am. https://docs.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.
回答1:
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
For more details, refer to this similar issue.
回答2:
The what you call userId is the Application Id (Also known as ClientID) of your service principal.
回答3:
The following really should work for you
$pscredential = Get-Credential
Connect-AzureRmAccount -ServicePrincipal -ApplicationId "http://my-app" -Credential $pscredential -TenantId $tenantid
Source: Microsoft Docs
来源:https://stackoverflow.com/questions/51719507/how-to-log-in-to-azure-service-principal