使用 PowerShell 创建要与 Azure 媒体服务 API 配合使用的 Azure AD 应用Use PowerShell to create an Azure AD app to use with the Azure Media Services API
备注
不会向媒体服务 v2 添加任何新特性或新功能。No new features or functionality are being added to Media Services v2.
查看最新版本:媒体服务 v3。Check out the latest version, Media Services v3. 另请参阅从 v2 到 v3 的迁移指南Also, see migration guidance from v2 to v3
了解如何使用 PowerShell 脚本创建 Azure Active Directory (Azure AD) 应用程序和服务主体,以访问 Azure 媒体服务资源。Learn how to use a PowerShell script to create an Azure Active Directory (Azure AD) application and service principal to access Azure Media Services resources.
先决条件Prerequisites
一个 Azure 帐户。An Azure account. 如果没有帐户,请从 Azure 试用版入手。If you don't have an account, start with an Azure trial.
一个媒体服务帐户。A Media Services account. 有关详细信息,请参阅在 Azure 门户中创建 Azure 媒体服务帐户。For more information, see Create an Azure Media Services account in the Azure portal.
Azure PowerShell。Azure PowerShell. 有关详细信息,请参阅如何使用 Azure PowerShell。For more information, see How to use Azure PowerShell.
备注
本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介。To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShell。For Az module installation instructions, see Install Azure PowerShell.
使用 PowerShell 创建 Azure AD 应用Create an Azure AD app by using PowerShell
Connect-AzAccount -EnvironmentName AzureChinaCloud
Import-Module Az.Resources
Set-AzContext -SubscriptionId $SubscriptionId
$ServicePrincipal = New-AzADServicePrincipal -DisplayName $ApplicationDisplayName -Password $Password
Get-AzADServicePrincipal -ObjectId $ServicePrincipal.Id
$NewRole = $null
$Scope = "/subscriptions/your subscription id/resourceGroups/userresourcegroup/providers/microsoft.media/mediaservices/your media account"
$Retries = 0;While ($NewRole -eq $null -and $Retries -le 6)
{
# Sleep here for a few seconds to allow the service principal application to become active (usually, it will take only a couple of seconds)
Sleep 15
New-AzRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $ServicePrincipal.ApplicationId -Scope $Scope | Write-Verbose -ErrorAction SilentlyContinue
$NewRole = Get-AzRoleAssignment -ServicePrincipalName $ServicePrincipal.ApplicationId -ErrorAction SilentlyContinue
$Retries++;
}
有关详细信息,请参阅以下文章:For more information, see the following articles:
- 使用 Azure PowerShell 创建服务主体来访问资源Use Azure PowerShell to create a service principal to access resources
- 使用 Azure PowerShell 添加或删除 Azure 角色分配Add or remove Azure role assignments using Azure PowerShell
- 如何使用证书手动配置守护程序应用How to manually configure daemon apps by using certificates
后续步骤Next steps
开始将文件上传到帐户。Get started with uploading files to your account.