Skip to content

Commit b83db77

Browse files
committed
updated scripts
1 parent 8f53a75 commit b83db77

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

articles/event-grid/scripts/powershell-webhook-secure-delivery-microsoft-entra-app.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ try {
3434
3535
Function CreateAppRole([string] $Name, [string] $Description)
3636
{
37-
$appRole = New-Object Microsoft.Open.AzureAD.Model.AppRole
37+
$appRole = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAppRole
3838
$appRole.AllowedMemberTypes = New-Object System.Collections.Generic.List[string]
39-
$appRole.AllowedMemberTypes.Add("Application");
40-
$appRole.AllowedMemberTypes.Add("User");
39+
$appRole.AllowedMemberTypes += "Application";
40+
$appRole.AllowedMemberTypes += "User";
4141
$appRole.DisplayName = $Name
4242
$appRole.Id = New-Guid
4343
$appRole.IsEnabled = $true
@@ -53,36 +53,35 @@ try {
5353
5454
$eventGridAppId = "4962773b-9cdb-44cf-a8bf-237846a00ab7" # Azure Public Cloud
5555
# $eventGridAppId = "54316b56-3481-47f9-8f30-0300f5542a7b" # Azure Government Cloud
56-
$eventGridRoleName = "AzureEventGridSecureWebhookSubscriber" # You don't need to modify this role name
5756
$eventGridSP = Get-MgServicePrincipal -Filter ("appId eq '" + $eventGridAppId + "'")
58-
if ($eventGridSP -match "Microsoft.EventGrid")
57+
if ($eventGridSP.DisplayName -match "Microsoft.EventGrid")
5958
{
60-
Write-Host "The Microsoft Entra Application is already defined.`n"
59+
Write-Host "The Event Grid Microsoft Entra Application is already defined.`n"
6160
} else {
6261
Write-Host "Creating the Azure Event Grid Microsoft Entra Application"
6362
$eventGridSP = New-MgServicePrincipal -AppId $eventGridAppId
6463
}
6564
6665
# Creates the Azure app role for the webhook Microsoft Entra application
67-
66+
$eventGridRoleName = "AzureEventGridSecureWebhookSubscriber" # You don't need to modify this role name
6867
$app = Get-MgApplication -ObjectId $webhookAppObjectId
6968
$appRoles = $app.AppRoles
7069
7170
Write-Host "Microsoft Entra App roles before addition of the new role..."
72-
Write-Host $appRoles
71+
Write-Host $appRoles.DisplayName
7372
74-
if ($appRoles -match $eventGridRoleName)
73+
if ($appRoles.DisplayName -match $eventGridRoleName)
7574
{
7675
Write-Host "The Azure Event Grid role is already defined.`n"
7776
} else {
7877
Write-Host "Creating the Azure Event Grid role in Microsoft Entra Application: " $webhookAppObjectId
7978
$newRole = CreateAppRole -Name $eventGridRoleName -Description "Azure Event Grid Role"
80-
$appRoles.Add($newRole)
81-
Update-MgApplication -ObjectId $app.ObjectId -AppRoles $appRoles
79+
$appRoles += $newRole
80+
Update-MgApplication -ApplicationId $webhookAppObjectId -AppRoles $appRoles
8281
}
8382
8483
Write-Host "Microsoft Entra App roles after addition of the new role..."
85-
Write-Host $appRoles
84+
Write-Host $appRoles.DisplayName
8685
8786
# Creates the user role assignment for the app that will create event subscription
8887

articles/event-grid/scripts/powershell-webhook-secure-delivery-microsoft-entra-user.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ Here are the high level steps from the script:
1818
1. Add service principal of user who is creating the subscription to the AzureEventGridSecureWebhookSubscriber role.
1919
1. Add service principal of Microsoft.EventGrid to the AzureEventGridSecureWebhookSubscriber.
2020

21-
## Sample script - stable
21+
## Sample script
2222

2323
```azurepowershell
2424
# NOTE: Before run this script ensure you are logged in Azure by using "az login" command.
2525
26-
$webhookAppObjectId = "[REPLACE_WITH_YOUR_ID]"
26+
$webhookAppId = "[REPLACE_WITH_YOUR_ID]"
2727
$eventSubscriptionWriterUserPrincipalName = "[REPLACE_WITH_USER_PRINCIPAL_NAME_OF_THE_USER_WHO_WILL_CREATE_THE_SUBSCRIPTION]"
2828
2929
# Start execution
@@ -33,10 +33,10 @@ try {
3333
3434
Function CreateAppRole([string] $Name, [string] $Description)
3535
{
36-
$appRole = New-Object Microsoft.Open.AzureAD.Model.AppRole
36+
$appRole = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAppRole
3737
$appRole.AllowedMemberTypes = New-Object System.Collections.Generic.List[string]
38-
$appRole.AllowedMemberTypes.Add("Application");
39-
$appRole.AllowedMemberTypes.Add("User");
38+
$appRole.AllowedMemberTypes += "Application";
39+
$appRole.AllowedMemberTypes += "User";
4040
$appRole.DisplayName = $Name
4141
$appRole.Id = New-Guid
4242
$appRole.IsEnabled = $true
@@ -52,36 +52,36 @@ try {
5252
5353
$eventGridAppId = "4962773b-9cdb-44cf-a8bf-237846a00ab7" # Azure Public Cloud
5454
# $eventGridAppId = "54316b56-3481-47f9-8f30-0300f5542a7b" # Azure Government Cloud
55-
$eventGridRoleName = "AzureEventGridSecureWebhookSubscriber" # You don't need to modify this role name
5655
$eventGridSP = Get-MgServicePrincipal -Filter ("appId eq '" + $eventGridAppId + "'")
57-
if ($eventGridSP -match "Microsoft.EventGrid")
56+
if ($eventGridSP.DisplayName -match "Microsoft.EventGrid")
5857
{
59-
Write-Host "The Microsoft Entra Application is already defined.`n"
58+
Write-Host "The Event Grid Microsoft Entra Application is already defined.`n"
6059
} else {
6160
Write-Host "Creating the Azure Event Grid Microsoft Entra Application"
6261
$eventGridSP = New-MgServicePrincipal -AppId $eventGridAppId
6362
}
6463
6564
# Creates the Azure app role for the webhook Microsoft Entra application
65+
$eventGridRoleName = "AzureEventGridSecureWebhookSubscriber" # You don't need to modify this role name
6666
67-
$app = Get-MgApplication -ObjectId $webhookAppObjectId
67+
$app = Get-MgApplication -ApplicationId $webhookAppObjectId
6868
$appRoles = $app.AppRoles
6969
7070
Write-Host "Microsoft Entra App roles before addition of the new role..."
71-
Write-Host $appRoles
71+
Write-Host $appRoles.DisplayName
7272
73-
if ($appRoles -match $eventGridRoleName)
73+
if ($appRoles.DisplayName -match $eventGridRoleName)
7474
{
7575
Write-Host "The Azure Event Grid role is already defined.`n"
7676
} else {
7777
Write-Host "Creating the Azure Event Grid role in Microsoft Entra Application: " $webhookAppObjectId
7878
$newRole = CreateAppRole -Name $eventGridRoleName -Description "Azure Event Grid Role"
79-
$appRoles.Add($newRole)
80-
Update-MgApplication -ObjectId $app.ObjectId -AppRoles $appRoles
79+
$appRoles += $newRole
80+
Update-MgApplication -ApplicationId $webhookAppObjectId -AppRoles $appRoles
8181
}
8282
8383
Write-Host "Microsoft Entra App roles after addition of the new role..."
84-
Write-Host $appRoles
84+
Write-Host $appRoles.DisplayName
8585
8686
# Creates the user role assignment for the user who will create event subscription
8787
@@ -90,9 +90,9 @@ try {
9090
try
9191
{
9292
Write-Host "Creating the Microsoft Entra App Role assignment for user: " $eventSubscriptionWriterUserPrincipalName
93-
$eventSubscriptionWriterUser = Get-MgUser -ObjectId $eventSubscriptionWriterUserPrincipalName
93+
$eventSubscriptionWriterUser = Get-MgUser -UserId $eventSubscriptionWriterUserPrincipalName
9494
$eventGridAppRole = $app.AppRoles | Where-Object -Property "DisplayName" -eq -Value $eventGridRoleName
95-
New-MgUserAppRoleAssignment -Id $eventGridAppRole.Id -ResourceId $servicePrincipal.ObjectId -ObjectId $eventSubscriptionWriterUser.ObjectId -PrincipalId $eventSubscriptionWriterUser.ObjectId
95+
New-MgUserAppRoleAssignment -Id $eventGridAppRole.Id -ResourceId $servicePrincipal.Id -UserId $eventSubscriptionWriterUser.Id -PrincipalId $eventSubscriptionWriterUser.Id
9696
}
9797
catch
9898
{
@@ -110,12 +110,12 @@ try {
110110
# Creates the service app role assignment for Event Grid Microsoft Entra Application
111111
112112
$eventGridAppRole = $app.AppRoles | Where-Object -Property "DisplayName" -eq -Value $eventGridRoleName
113-
New-MgServicePrincipalAppRoleAssignment -Id $eventGridAppRole.Id -ResourceId $servicePrincipal.ObjectId -ObjectId $eventGridSP.ObjectId -PrincipalId $eventGridSP.ObjectId
113+
New-MgServicePrincipalAppRoleAssignment -Id $eventGridAppRole.Id -ResourceId $servicePrincipal.Id -ServicePrincipalId $eventGridSP.Id -PrincipalId $eventGridSP.Id
114114
115115
# Print output references for backup
116116
117117
Write-Host ">> Webhook's Microsoft Entra Application Id: $($app.AppId)"
118-
Write-Host ">> Webhook's Microsoft Entra Application ObjectId Id: $($app.ObjectId)"
118+
Write-Host ">> Webhook's Microsoft Entra Application Object Id: $($app.Id)"
119119
}
120120
catch {
121121
Write-Host ">> Exception:"

0 commit comments

Comments
 (0)