Skip to content

Commit 6428112

Browse files
committed
fixes
1 parent 0bfbc65 commit 6428112

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

articles/virtual-network/create-peering-different-subscriptions-service-principal.md

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Create **spn1-peer-vnet** with a scope to the virtual network created in the pre
254254
1. The service principal must have **User.Read.All** permissions to the directory. Use [Get-AzureADApplication](/powershell/module/azuread/get-azureadapplication), [Set-AzureADApplication](/powershell/module/azuread/set-azureadapplication), and [New-AzureADUserAppRoleAssignment](/powershell/module/azuread/new-azureaduserapproleassignment) to add the Microsoft Graph permissions of **User.Read.all** to the service principal.
255255
256256
```azurepowershell
257-
$appId1 = Get-AzureADApplication -Filter "DisplayName eq 'spn-1-peer-vnet'" | Select-Object ObjectId
257+
$appId1 = Get-AzureADApplication -Filter "DisplayName eq 'spn-1-peer-vnet'"
258258
259259
# Define the permission
260260
$apiPermission = New-Object -TypeName Microsoft.Open.AzureAD.Model.RequiredResourceAccess
@@ -263,46 +263,18 @@ Create **spn1-peer-vnet** with a scope to the virtual network created in the pre
263263
$apiPermission.ResourceAccess = $resourceAccess
264264
265265
# Get the application
266-
$app = Get-AzureADApplication -ObjectId $appid1.ObjectId
266+
$app = Get-AzureADApplication -ObjectId $appId1.ObjectId
267267
268268
# Add the permission
269269
$app.RequiredResourceAccess.Add($apiPermission)
270270
271271
# Update the application
272-
Set-AzureADApplication -ObjectId $appid1.ObjectId -RequiredResourceAccess $app.RequiredResourceAccess
272+
Set-AzureADApplication -ObjectId $appId1.ObjectId -RequiredResourceAccess $app.RequiredResourceAccess
273273
274-
275-
276-
277-
278-
# Add permission
279-
280-
$apiPermission = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.RequiredResourceAccess'
281-
282-
$apiPermission.ResourceAppId = "00000003-0000-0000-c000-000000000000"
283274
284-
$access = @{
285-
TypeName = 'Microsoft.Open.AzureAD.Model.ResourceAccess'
286-
Property = @{
287-
Id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d"
288-
Type = "Scope"
289-
}
290-
}
291-
$resourceAccess = New-Object @access
292-
293-
$apiPermission.ResourceAccess = $resourceAccess
294275
295-
$appId1 = Get-AzureADApplication -Filter "DisplayName eq 'spn-1-peer-vnet'" | Select-Object ObjectId
296276
297-
$app = Get-AzureADApplication -ObjectId $appid1.ObjectId
298277
299-
$app.RequiredResourceAccess.Add($apiPermission)
300-
301-
$setapp = @{
302-
ObjectId = $appid1.ObjectId
303-
RequiredResourceAccess = $app.RequiredResourceAccess
304-
}
305-
Set-AzureADApplication @setapp
306278
307279
# Grant permission
308280
$sp = Get-AzureADServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
@@ -311,7 +283,7 @@ Create **spn1-peer-vnet** with a scope to the virtual network created in the pre
311283
$userReadPermission = $sp.AppRoles | Where-Object {$_.Value -eq 'User.Read.All'}
312284
313285
# Grant the permission
314-
New-AzureADUserAppRoleAssignment -ObjectId $app -PrincipalId $app -ResourceId $sp.ObjectId -Id $userReadPermission.Id
286+
New-AzureADUserAppRoleAssignment -ObjectId $appId1.ObjectId -PrincipalId $appId1.ObjectId -ResourceId $sp.ObjectId -Id $userReadPermission.Id
315287
```
316288
317289
---

0 commit comments

Comments
 (0)