私はリソースグループを作成し、含まれているアプリケーション(この例ではWeb Api)を関連するAADに登録するPowerShellスクリプトを作成しています。 しかし、Reader
の権利を割り当てようと呼び出すと、失敗し続けます。AzureAD PowerShell New-AzureRmRoleAssignmentが失敗し続ける
Visual Studio(2015)でAzureResourceGroupテンプレートに付属する基本的な展開* .ps1ファイルから始めました。
#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
最後のコマンド(New-AzureRmRoleAssignment
)は次のエラーで失敗し続け:
私は次のコードを実行しているよ
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
通常は、私がデプロイを使用してこのスクリプトを実行しますVisual Studioのオプション。 Microsoft Azure PowerShell
コマンドウィンドウからこのスクリプトを実行すると、同じエラーが発生します。
しかし、私は同じパワーシェルウィンドウで正確なコマンドを実行すると、それは動作します!
New-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName <ApplicationId>
ps1ファイル内でこれが失敗する理由は誰にも分かりますか?私もスコープを明示的に定義しようとしましたが、それはやっていませんでした。
リトライロジックを追加する必要があることがわかりました。作成が完了するまでに30秒かかることがあったので、役割を追加できました –