天天看點

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

問題描述

powershell 調用New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred,出現如下錯誤: Resource not found for the segment 'me'.

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

Powershell 腳本為:

# Login to China Azure
 $username="[email protected]"
 $password="xxxxxxxxxxxx"
 $pscredential = New-Object System.Management.Automation.PSCredential($username, $password)
 $tenantId=""
 $region="AzureChinaCloud"

Connect-AzAccount -ServicePrincipal -Credential $pscredential -TenantId $tenantId -Environment $region
$azContext = Set-AzContext -SubscriptionId "" -Tenant ""

$credentials = New-Object -TypeName Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential -Property @{StartDate=Get-Date; EndDate=Get-Date -Year 2024; Password='StrongPassworld!23'}
$sp = New-AzAdServicePrincipal -DisplayName ServicePrincipalName -PasswordCredential $credentials      

問題分析

在雲上遇見問題後,可以反向在本地測試運作,看是否能遇見相同的問題。從錯誤消息可以定位到是否目前所登入賬号的權限問題,可以用下面的步驟來檢查或賦予權限:

第一步:在Azure Active Directory中選擇應用注冊,然後選擇角色和管理者,點選“在需要時,使用PIM實時通路角色,詳細了解PIM”

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

第二步:選擇AzureAD角色

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

第三步:點選配置設定資格

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

第四步:選擇角色,點選添加配置設定

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

第五步:選擇角色,選擇成員,輸入應用的名稱或者clientid點選選擇,點選下一步。

【Azure 應用服務】azure function powershell 調用 New-AzADServicePrincipal -DisplayName $sp -PasswordCredential $spCred

第六步:儲存配置設定成功,即可在Azure Active Directory中的角色和管理者中找到該角色點選配置設定中檢視到應用

參考資料

PIM(Privileged Identity Management)配置設定:https://docs.azure.cn/zh-cn/active-directory/privileged-identity-management/groups-assign-member-owner?view=azs-2102

應用程式管理者:https://docs.azure.cn/zh-cn/active-directory/roles/permissions-reference?view=azs-2102#application-administrator

當在複雜的環境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 雲中,恰是如此!

繼續閱讀