Microsoft ID プラットフォームがMicrosoft EntraまたはMicrosoft 365テナントに格納されているデータにアクセスすることを承認するには、アプリをMicrosoft Entra IDに登録する必要があります。 この条件は、自分で開発したアプリ、テナントが所有しているアプリ、またはアクティブなサブスクリプションを介してアクセスするアプリに適用されます。
アプリの多くの設定は、Microsoft Entra PowerShell を使用してアクセス、更新、または削除できるオブジェクトとして記録されます。 これらのオブジェクトには、アプリケーション、サービス プリンシパル、アプリ ロールの割り当てが含まれます。
この記事では、PowerShell を使用してアプリの登録とサービス プリンシパル オブジェクトMicrosoft Entra管理する方法について説明します。 アプリケーションの登録、プロパティの構成、アクセス許可の割り当て、アプリの所有権の管理について説明します。
前提条件
Microsoft Entra PowerShell でアプリを管理するには、次のものが必要です。
- Microsoft Entra ユーザー アカウント。 まだアカウントがない場合は、無料でアカウントを作成することができます。
- 次のいずれかのロール:
- その操作に必要な最小特権の委任されたアクセス許可を自分に付与します。
- Microsoft Entra PowerShell モジュールがインストールされています。 PowerShell モジュールMicrosoft Entraインストール ガイドに従って、モジュールをインストールします。
アプリケーションを登録する
次の要求では、必要な displayName プロパティのみを指定してアプリを作成します。
Connect-Entra -Scopes 'Application.ReadWrite.All'
New-EntraApplication -DisplayName 'My new application'
DisplayName Id AppId SignInAudience PublisherDomain
----------- -- ----- -------------- -----------
My new application aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb bbbbbbbb-1111-2222-3333-cccccccccccc MyOrg
アプリケーションには、テナント内のアプリに固有の ID と、Microsoft Entra エコシステム内でグローバルに一意の appId が割り当てられます。
アプリケーションのサービス プリンシパルを作成する
Connect-Entra -Scopes 'Application.ReadWrite.All'
$myApp = Get-EntraApplication -Filter "DisplayName eq 'My new application'"
New-EntraServicePrincipal -AppId $myApp.AppId -DisplayName 'My new service principal'
DisplayName Id AppId SignInAudience ServicePrincipalType
----------- -- ----- -------------- --------------------
My new application bbbbbbbb-1111-2222-3333-cccccccccccc 00001111-aaaa-2222-bbbb-3333cccc4444 MyOrg Application
アプリの基本プロパティを構成する
アプリの複数のプロパティを構成できます。 次の例は、アプリケーションの表示名を更新する方法を示しています。
Connect-Entra -Scopes 'Application.ReadWrite.All'
$application = Get-EntraApplication -Filter "DisplayName eq 'My new application'"
Set-EntraApplication -ApplicationId $application.Id -DisplayName 'Contoso application'
または、パイプライン処理を使用して、アプリケーションのプロパティを更新します。
Connect-Entra -Scopes 'Application.ReadWrite.All'
Get-EntraApplication -Filter "DisplayName eq 'My new application'" | Set-EntraApplication -DisplayName 'Contoso application'
詳細については、「 Set-EntraApplication」を参照してください。
アプリのサインインを割り当てられた ID のみに制限する
Microsoft Entra PowerShell を使用してアプリのサインインを割り当てられた ID のみに制限することで、承認されたユーザーのみがアプリケーションにアクセスでき、セキュリティと制御が強化されます。
Connect-Entra -Scopes 'Application.ReadWrite.All'
$application = Get-EntraApplication -Filter "DisplayName eq 'My new application'"
Set-EntraServicePrincipal -ServicePrincipalId $application.Id -AppRoleAssignmentRequired $true
アプリにアクセス許可を割り当てる
アプリにアクセス許可を割り当てるには、Microsoft Entra 管理センターを使用するか、Microsoft Entra PowerShell を使用します。 PowerShell では、既存のアクセス許可と新しいアクセス許可の両方を含む、アプリの requiredResourceAccess プロパティを更新します。 新しいアクセス許可のみを渡すと、同意されていない既存のアクセス許可が削除されます。
アクセス許可を割り当てても、自動的にアプリに付与されることはありません。 引き続き、Microsoft Entra 管理センターを使用して管理者の同意を付与する必要があります。
Connect-Entra -Scopes 'Application.ReadWrite.All'
$application = Get-EntraApplication -Filter "DisplayName eq 'My new application'"
$requiredResourceAccess = @(
@{resourceAppId = '00000003-0000-0000-c000-000000000000'
resourceAccess = @(
@{
id = 'c79f8feb-a9db-4090-85f9-90d820caa0eb'
type = 'Scope'
}
@{
id = '9a5d68dd-52b0-4cc2-bd40-abcf44ac3a30'
type = 'Role'
} )
})
Set-EntraApplication -ApplicationId $application.Id -RequiredResourceAccess $requiredResourceAccess
所有者を管理
サービス プリンシパルの所有者を取得する
Connect-Entra -Scopes 'Application.ReadWrite.All'
$servicePrincipal = Get-EntraServicePrincipal -Filter "displayName eq 'Helpdesk Application'"
Get-EntraServicePrincipalOwner -ServicePrincipalId $servicePrincipal.Id -All | Select-Object Id, DisplayName, '@odata.type'
別の方法として、パイプラインを使用してサービス プリンシパルの所有者を取得します。
Get-EntraServicePrincipal -Filter "displayName eq 'Helpdesk Application'" | Get-EntraServicePrincipalOwner | Select-Object Id, DisplayName, '@odata.type'
サービス プリンシパルに所有者を割り当てる
Connect-Entra -Scopes 'Application.ReadWrite.All', 'Application.ReadWrite.OwnedBy'
$servicePrincipal = Get-EntraServicePrincipal -Filter "displayName eq 'Helpdesk Application'"
$owner = Get-EntraUser -UserId 'SawyerM@contoso.com'
Add-EntraServicePrincipalOwner -ServicePrincipalId $servicePrincipal.Id -OwnerId $owner.Id
この例では、サービス プリンシパルに所有者を追加する方法を示します。
-
-ServicePrincipalId- 所有者を追加するサービス プリンシパルの一意の識別子 (ObjectId) を指定します。 -
-OwnerId- 指定されたサービス プリンシパルの所有者として追加するユーザーまたはグループの一意の識別子 (ObjectId) を指定します。
ユーザー割り当てなしですべてのアプリケーションの一覧を取得する
ユーザーの割り当てを必要としないすべてのアプリケーションの一覧を取得するには、次のコマンドを使用します。
Connect-Entra -Scopes 'Application.ReadWrite.All'
Get-EntraServicePrincipal -All | Where-Object {$_.appRoleAssignmentRequired -ne 'True'}
DisplayName Id AppId SignInAudience ServicePrincipalType
----------------------------------- ----------------------------------- --------------------------------- ----------------- ------------------
Microsoft password reset service 00aa00aa-bb11-cc22-dd33-44ee44ee44ee 93625bc8-bfe2-437a-97e0-3d0060024faa AzureADMultipleOrgs Application
Microsoft.Azure.SyncFabric 11bb11bb-cc22-dd33-ee44-55ff55ff55ff 00000014-0000-0000-c000-000000000000 AzureADMultipleOrgs Application
Azure Security Insights 22cc22cc-dd33-ee44-ff55-66aa66aa66aa 98785600-1bb7-4fb9-b9fa-19afe2c8a360 AzureADMultipleOrgs Application
サービス プリンシパルによって所有または作成されたオブジェクトの取得
サービス プリンシパルによって作成されたオブジェクト
Connect-Entra -Scopes 'Application.Read.All'
$servicePrincipal = Get-EntraServicePrincipal -Filter "displayName eq 'Helpdesk Application'"
Get-EntraServicePrincipalCreatedObject -ServicePrincipalId $servicePrincipal.Id
サービス プリンシパルが所有するオブジェクト
Connect-Entra -Scopes 'Application.Read.All'
$servicePrincipal = Get-EntraServicePrincipal -Filter "displayName eq 'Helpdesk Application'"
Get-EntraServicePrincipalOwnedObject -ServicePrincipalId $servicePrincipal.Id -All | Select-Object Id, DisplayName, '@odata.type'
期限切れのシークレットと証明書を含むアプリケーション
アプリケーション シークレットまたはパスワードの期限切れ
$expirationThreshold = (Get-Date).AddDays(30)
$appsWithExpiringPasswords = Get-EntraApplication -All | Where-Object { $_.PasswordCredentials } |
ForEach-Object {
$app = $_
$app.PasswordCredentials | Where-Object { $_.EndDate -le $expirationThreshold } |
ForEach-Object {
[PSCustomObject]@{
DisplayName = $app.DisplayName
AppId = $app.AppId
SecretDisplayName = $_.DisplayName
KeyId = $_.KeyId
ExpiringSecret = $_.EndDate
}
}
}
$appsWithExpiringPasswords | Format-Table DisplayName, AppId, SecretDisplayName, KeyId, ExpiringSecret -AutoSize
証明書の期限切れ
$expirationThreshold = (Get-Date).AddDays(30)
$appsWithExpiringKeys = Get-EntraApplication -All | Where-Object { $_.KeyCredentials } |
ForEach-Object {
$app = $_
$app.KeyCredentials | Where-Object { $_.EndDate -le $expirationThreshold } |
ForEach-Object {
[PSCustomObject]@{
DisplayName = $app.DisplayName
AppId = $app.AppId
CertificateDisplayName = $_.DisplayName
KeyId = $_.KeyId
ExpiringKeys = $_.EndDate
}
}
}
$appsWithExpiringKeys | Format-Table DisplayName, AppId, CertificateDisplayName, KeyId, ExpiringKeys -AutoSize