I am working on a powershell script that will create a resource group, register the included application (in this example, Web Api) for the associated AAD. But with a call trying to assign Reader rights, it continues to fail.
I started with the main * .ps1 deployment file, which comes with the AzureResourceGroup template in Visual Studio (2015).
I run the following code:
#Requires -Version 3.0 #Requires -Module AzureRM.Resources #Requires -Module Azure.Storage Import-Module Azure -ErrorAction SilentlyContinue Set-StrictMode -Version 3 Login-AzureRmAccount $tenantWebSite = New-AzureRmADApplication -DisplayName "TheSiteName" -HomePage "http://MySignOnUrl" -IdentifierUris "http://MyIdentifierUrl" -Password "MyClientSecret" $tenantWebSiteServicePrincipal = New-AzureRmADServicePrincipal -ApplicationId $tenantWebSite.ApplicationId New-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName $tenantWebSite.ApplicationId
This last command ( New-AzureRmRoleAssignment ) continues to fail with the following error:
09:58:26 - [ERROR] New-AzureRmRoleAssignment : PrincipalNotFound: Principal 09:58:26 - [ERROR] 50f3d430c68b485b8c11a63552171550 does not exist in the directory 09:58:26 - [ERROR] <MyTenantId>. 09:58:26 - [ERROR] At D:\dev_new_2010\cto\src\dev\d.tom.0\deploy\calidos.maat.deploy.azureresource 09:58:26 - [ERROR] group\Scripts\Deploy-AzureResourceGroup.ps1:115 char:1 09:58:26 - [ERROR] + New-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipa ... 09:58:26 - [ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 09:58:26 - [ERROR] + CategoryInfo : CloseError: (:) [New-AzureRmRoleAssignment], Clo 09:58:26 - [ERROR] udException 09:58:26 - [ERROR] + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureRoleA 09:58:26 - [ERROR] ssignmentCommand
I usually run this script using the deployment option in visual studio. When I run this script from the Microsoft Azure PowerShell command window, I get the same error.
BUT, when I run the exact command in the same powershell window, it works!
New-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName <ApplicationId>
Does anyone have an idea on why this could come from a ps1 file? I also tried to explicitly define the scope, but that didn't help either.
source share