我想使用 Web 作业重启应用服务。我已经编写了一个电源外壳脚本。使用服务主体与 Azure 的连接返回空订阅 ID,订阅名称下面是我的代码:
我已经尝试了下面的代码。当我手动连接时。整个过程有效。但我需要通过服务原则来实现它
$azureAplicationId =""
$azureTenantId= ""
$azurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
Restart-AzureRmWebApp -ResourceGroupName "devRG" -Name "draftfoxdatamanagementdev"
错误:
Account : Got details
SubscriptionName :
SubscriptionId :
TenantId : got details
Environment : got details
Restart-AzureRmWebApp : 'this.Client.SubscriptionId' cannot be null.
At C:Userstingu.marina.johnDocumentstestingservice.ps1:6 char:1
+ Restart-AzureRmWebApp -ResourceGroupName "devRG" -Name "draftfoxdatam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Restart-AzureRmWebApp], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.RestartAzureWebAppCmdlet
此脚本应该可以工作,假设你尚未将服务主体添加为订阅/Web 应用中的 RBAC 角色。
若要解决此问题,请询问订阅的Owner
导航到门户中的订阅/Web 应用> Access control (IAM)
>单击Add
> Add role assignment
>将服务主体添加为角色(例如 Owner
, Contributor
(,有关更多详细信息,请参阅此链接。