Entra ID

Entra PowerShell

To work with Enterprise Applications in Azure using PowerShell, particularly for Entra ID (previously Azure AD), you’ll typically use the AzureAD or Microsoft.Graph module for interacting with these resources. Below is an example of a PowerShell script that demonstrates how to interact with an Enterprise Application in Entra ID using the Microsoft.Graph module.

Prerequisites


Example Script for Managing Enterprise Applications

This script will cover basic tasks, such as:

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Application.ReadWrite.All", "Directory.ReadWrite.All"

# Get all Enterprise Applications
$enterpriseApps = Get-MgServicePrincipal

# Display list of Enterprise Applications (Service Principals)
$enterpriseApps | Select DisplayName, AppId, Id

# Example: Get details of a specific Enterprise Application by AppId
$appId = "your-app-id-here"  # Replace with your Enterprise Application's AppId
$enterpriseApp = Get-MgServicePrincipal -ServicePrincipalId $appId

# Display details of the specific Enterprise Application
$enterpriseApp | Format-List DisplayName, AppId, Id, Description, AppRoleAssignedTo

# Example: Assign a role to the Enterprise Application
# First, find the role you want to assign
$roles = Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $enterpriseApp.Id

# Display available roles
$roles | Select AppRoleId, PrincipalDisplayName, ResourceDisplayName

# Assign role (if necessary)
# Example: You'd assign a role like this (adjust based on your needs):
$roleId = "role-id"  # Replace with actual role ID
$resourceId = "resource-id"  # Replace with resource (service) ID

New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $enterpriseApp.Id -AppRoleId $roleId -ResourceId $resourceId

Write-Host "Role Assigned Successfully!"

Key Concepts


More advanced operations you can perform