forked from Gerenios/AADInternals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureManagementAPI.ps1
788 lines (671 loc) · 28.1 KB
/
AzureManagementAPI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# Get users using Azure Management API
# Oct 23rd 2018
function Get-AzureManagementUsers
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken
)
Process
{
$response=Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Users?searchText=&top=100&nextLink=&orderByThumbnails=false&maxThumbnailCount=999&filterValue=All&state=All&adminUnit="
return $response.items
}
}
# Creates an user using Azure Management API
# Oct 23rd 2018
function New-AzureManagementUser
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$True)]
[string]$UserPrincipalnName,
[Parameter(Mandatory=$True)]
[string]$DisplayName,
[Parameter(Mandatory=$True)]
[string]$Password,
[switch]$GlobalAdmin
)
Process
{
$pwdProfile=@{
"forceChangePasswordNextLogin"="False"
"password"=$Password
}
$rolesEntity=""
if($GlobalAdmin)
{
$rolesEntity=@{
"adminType"="3" # Global Admin
"enabledRoles"=""
}
}
$Body=@{
"displayName" = $DisplayName
"userPrincipalName" = $UserPrincipalnName
"passwordProfile" = $pwdProfile
"rolesEntity" = $rolesEntity
}
return Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "UserDetails" -Body $Body -Method "Post"
}
}
# Removes the given user using Azure Management API
# Oct 23rd 2018
function Remove-AzureManagementUser
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$True)]
[string]$ObjectId
)
Process
{
return Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Users/$ObjectId" -Method Delete
}
}
# Removes the given users using Azure Management API
# Oct 23rd 2018
function Remove-AzureManagementUsers
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$True)]
[string[]]$ObjectIds
)
Process
{
return Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Users" -Method Delete -Body $ObjectIds
}
}
# Checks whether the external user is unique or already exists in AAD
# Oct 23rd 2018
function Is-ExternalUserUnique
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$True)]
[string]$EmailAddress
)
Process
{
return Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Users/IsUPNUniqueOrPending/$EmailAddress"
}
}
# Invites an external user to AAD
# Oct 23rd 2018
function New-GuestInvitation
{
<#
.SYNOPSIS
Invites an user to AAD
.DESCRIPTION
Invites an user to AAD using Azure Management API
.Parameter AccessToken
Auth Token
.Parameter EmailAddress
Email address of the guest user
.Parameter Message
The message to be sent with the invitation
.Example
PS C:\>$cred=Get-Credential
PS C:\>Get-AADIntAccessTokenForAADIAMAPI -Credentials $cred
PS C:\>New-AADIntGuestInvitation -EmailAddress someone@company.com -Message "Welcome to our Tenant!"
accountEnabled : True
usageLocation :
mailNickname : someone_company.com#EXT#
passwordProfile :
rolesEntity :
selectedGroupIds :
streetAddress :
city :
state :
country :
telephoneNumber :
mobile :
physicalDeliveryOfficeName :
postalCode :
authenticationPhoneNumber :
authenticationAlternativePhoneNumber :
authenticationEmail :
strongAuthenticationDetail : @{verificationDetail=}
defaultImageUrl :
ageGroup :
consentProvidedForMinor :
legalAgeGroupClassification :
objectId : e550c8f5-aff3-4eea-9d68-cff019fa850e
objectType : User
displayName : someone
userPrincipalName : someone_company.com#EXT#@company.onmicrosoft.com
thumbnailPhoto@odata.mediaContentType :
givenName :
surname :
mail : someone@company.com
dirSyncEnabled :
alternativeSecurityIds : {}
signInNamesInfo : {}
signInNames : {someone_company.com#EXT#@company.onmicrosoft.com}
ownedDevices :
jobTitle :
department :
displayUserPrincipalName :
hasThumbnail : False
imageUrl :
imageDataToUpload :
source :
sources :
sourceText :
userFlags :
deletionTimestamp :
permanentDeletionTime :
alternateEmailAddress :
manager :
userType : Guest
isThumbnailUpdated :
isAuthenticationContactInfoUpdated :
searchableDeviceKey : {}
displayEmail :
creationType : Invitation
userState : PendingAcceptance
otherMails : {someone@company.com}
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$True)]
[string]$EmailAddress,
[Parameter(Mandatory=$False)]
[string]$Message
)
Process
{
$UserToInvite = @{
"displayName"=$EmailAddress
"userPrincipalName" = $EmailAddress
"givenName" = "null"
"surname" = "null"
"jobTitle" = "null"
"department" = "null"
"passwordProfile" = ""
"selectedGroupIds" = ""
"rolesEntity" = ""
}
$Body=@{
"userToInvite"=$UserToInvite
"inviteMessage"=$Message
}
return Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Users/Invite" -Method "Put" -Body $Body
}
}
# Sets the user as Global Admin
# Oct 23rd 2018
function Set-AzureManagementAdminRole
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$True)]
[string]$ObjectId
)
Process
{
$Role=@{
"62e90394-69f5-4237-9190-012177145e10" = "25b21f4a-977e-49f2-9de4-2c885f30be5d"
}
return Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Roles/User/$ObjectId" -Method "Put" -Body $Role
}
}
# Gets azure activity log
# Oct 23rd 2018
function Get-AzureActivityLog
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
$AccessToken,
[Parameter(Mandatory=$False)]
[datetime]$Start=$((Get-Date).AddDays(-30)),
[Parameter(Mandatory=$False)]
[datetime]$End=$(Get-Date)
)
Process
{
$Body=@{
"startDateTime" = $Start.ToUniversalTime().ToString("o")
"endDateTime" = $End.ToUniversalTime().ToString("o")
}
$response = Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Reports/SignInEventsV2" -Method Post -Body $Body
# Return
$response.items
}
}
# Get user's Azure AD tenants
# Jul 11th 2019
function Get-UserTenants
{
<#
.SYNOPSIS
Returns tenants the given user is member of
.DESCRIPTION
Returns tenants the given user is member of using Azure Management API
.Example
$at=Get-AccessTokenForAzureMgmtAPI -Credentials $cred
PS C:\> Get-UserTenants -AccessToken $at
Get-AADIntLoginInformation -Domain outlook.com
id : 3087e687-0d37-4c21-87c5-ecac88f0374a
domainName : company.onmicrosoft.com
displayName : Company Ltd
isSignedInTenant : True
tenantCategory :
id : 2968be53-ede5-4e30-844a-96d66479fb10
domainName : company2.onmicrosoft.com
displayName : Company2
isSignedInTenant : False
tenantCategory :
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource azureportal
$response=Call-AzureManagementAPI -AccessToken $AccessToken -Command "directories/List"
return $response.tenants
}
}
# Gets Azure Tenant information as a guest user
# Jun 11th 2020
function Get-AzureInformation
{
<#
.SYNOPSIS
Gets some Azure Tenant information.
.DESCRIPTION
Gets some Azure Tenant information, including certain tenant settings and ALL domains. The access token MUST be
stored to cache! Works also for guest users.
The Tenant is not required for Access Token but is recommended as some tenants may have MFA.
.Example
Get-AADIntAccessTokenForAzureCoreManagement -Tenant 6e3846ee-e8ca-4609-a3ab-f405cfbd02cd -SaveToCache
Tenant User Resource Client
------ ---- -------- ------
6e3846ee-e8ca-4609-a3ab-f405cfbd02cd https://management.core.windows.net/ d3590ed6-52b3-4102-aeff-aad2292ab01c
PS C:\>Get-AADIntAzureTenants
Id Country Name Domains
-- ------- ---- -------
221769d7-0747-467c-a5c1-e387a232c58c FI Firma Oy {firma.mail.onmicrosoft.com, firma.onmicrosoft.com, firma.fi}
6e3846ee-e8ca-4609-a3ab-f405cfbd02cd US Company Ltd {company.onmicrosoft.com, company.mail.onmicrosoft.com,company.com}
PS C:\>Get-AADIntAzureInformation -Tenant
objectId : 6e3846ee-e8ca-4609-a3ab-f405cfbd02cd
displayName : Company Ltd
usersCanRegisterApps : True
isAnyAccessPanelPreviewFeaturesAvailable : False
showMyGroupsFeature : False
myGroupsFeatureValue :
myGroupsGroupId :
myGroupsGroupName :
showMyAppsFeature : False
myAppsFeatureValue :
myAppsGroupId :
myAppsGroupName :
showUserActivityReportsFeature : False
userActivityReportsFeatureValue :
userActivityReportsGroupId :
userActivityReportsGroupName :
showRegisteredAuthMethodFeature : False
registeredAuthMethodFeatureValue :
registeredAuthMethodGroupId :
registeredAuthMethodGroupName :
usersCanAddExternalUsers : False
limitedAccessCanAddExternalUsers : False
restrictDirectoryAccess : False
groupsInAccessPanelEnabled : False
selfServiceGroupManagementEnabled : True
securityGroupsEnabled : False
usersCanManageSecurityGroups :
office365GroupsEnabled : False
usersCanManageOfficeGroups :
allUsersGroupEnabled : False
scopingGroupIdForManagingSecurityGroups :
scopingGroupIdForManagingOfficeGroups :
scopingGroupNameForManagingSecurityGroups :
scopingGroupNameForManagingOfficeGroups :
objectIdForAllUserGroup :
allowInvitations : False
isB2CTenant : False
restrictNonAdminUsers : False
enableLinkedInAppFamily : 0
toEnableLinkedInUsers : {}
toDisableLinkedInUsers : {}
linkedInSelectedGroupObjectId :
linkedInSelectedGroupDisplayName :
allowedActions : @{application=System.Object[]; domain=System.Object[]; group=System.Object[]; serviceprincipal=System.Object[];
tenantdetail=System.Object[]; user=System.Object[]; serviceaction=System.Object[]}
skuInfo : @{aadPremiumBasic=False; aadPremium=False; aadPremiumP2=False; aadBasic=False; aadBasicEdu=False; aadSmb=False;
enterprisePackE3=False; enterprisePremiumE5=False}
domains : {@{authenticationType=Managed; availabilityStatus=; isAdminManaged=True; isDefault=False; isDefaultForCloudRedirections=False;
isInitial=False; isRoot=True; isVerified=True; name=company.com; supportedServices=System.Object[]; forceDeleteState=; state=;
passwordValidityPeriodInDays=; passwordNotificationWindowInDays=}, @{authenticationType=Managed; availabilityStatus=;
isAdminManaged=True; isDefault=False; isDefaultForCloudRedirections=False; isInitial=True; isRoot=True; isVerified=True;
name=company.onmicrosoft.com;}...}
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$Tenant
)
Begin
{
$guestAccessPolicies = @{
"a0b1b346-4d3e-4e8b-98f8-753987be4970" = "Full"
"10dae51f-b6af-4016-8d66-8c2a99b929b3" = "Normal"
"2af84b1e-32c8-42b7-82bc-daa82404023b" = "Restricted"
}
}
Process
{
# Get from cache
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "https://management.core.windows.net/" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c"
# Get the refreshtoken
$refresh_token=$script:refresh_tokens["d3590ed6-52b3-4102-aeff-aad2292ab01c-https://management.core.windows.net/"]
if([string]::IsNullOrEmpty($refresh_token))
{
Throw "No refreshtoken found! Use Get-AADIntAccessTokenForAzureCoreManagement with -SaveToCache switch."
}
# Get the tenants
if([string]::IsNullOrEmpty($Tenant))
{
$tenants = Get-AzureTenants $AccessToken
}
else
{
$tenants = @(New-Object psobject -Property @{"Id" = $Tenant})
}
# Loop through the tenants
foreach($tenant_info in $tenants)
{
# Create a new AccessToken for Azure AD management portal API
$access_token = Get-AccessTokenWithRefreshToken -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c" -TenantId $tenant_info.Id -RefreshToken $refresh_token -SaveToCache $true
# Directory information included in properties
#$directory = Call-AzureAADIAMAPI -AccessToken $access_token -Command "Directory"
$properties = Call-AzureAADIAMAPI -AccessToken $access_token -Command "Directories/Properties"
if($properties.restrictNonAdminUsers -ne "True") # If restricted, don't bother trying
{
$permissions = Call-AzureAADIAMAPI -AccessToken $access_token -Command "Permissions?forceRefresh=false"
}
$skuinfo = Call-AzureAADIAMAPI -AccessToken $access_token -Command "TenantSkuInfo"
# Create a new AccessToken for graph.windows.net
$access_token2 = Get-AccessTokenWithRefreshToken -Resource "https://graph.windows.net/" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c" -TenantId $tenant_info.Id -RefreshToken $refresh_token -SaveToCache $true
# Get the domain details
#$response = Invoke-RestMethod -UseBasicParsing -Method Get -Uri "https://graph.windows.net/myorganization/domains?api-version=1.61-internal" -Headers @{"Authorization"="Bearer $access_token2"}
#$domains = $response.Value
# Create a new AccessToken for graph.microsoft.com
$access_token3 = Get-AccessTokenWithRefreshToken -Resource "https://graph.microsoft.com" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c" -TenantId $tenant_info.Id -RefreshToken $refresh_token -SaveToCache $true
# Get the directory quota
$response2 = Invoke-RestMethod -UseBasicParsing -Uri "https://main.iam.ad.ext.azure.com/api/MsGraph/v1.0/organization/?`$select=directorySizeQuota" -Headers @{"Authorization" = "Bearer $access_token3"}
# Get the domain details
$domains = Get-MSGraphDomains -AccessToken $access_token3
# Get the tenant authorization policy
try
{
$authPolicy = Get-TenantAuthPolicy -AccessToken $access_token3
$guestAccess = $guestAccessPolicies[$authPolicy.guestUserRoleId]
}
catch{}
# Get Conditional access policies
$CAPolicy = Get-ConditionalAccessPolicies -AccessToken $access_token2
# Construct the return value
$properties | Add-Member -NotePropertyName "allowedActions" -NotePropertyValue $permissions.allowedActions
$properties | Add-Member -NotePropertyName "skuInfo" -NotePropertyValue $skuInfo
$properties | Add-Member -NotePropertyName "domains" -NotePropertyValue $domains
$properties | Add-Member -NotePropertyName "directorySizeQuota" -NotePropertyValue $response2.value[0].directorySizeQuota
$properties | Add-Member -NotePropertyName "authorizationPolicy" -NotePropertyValue $authPolicy
$properties | Add-Member -NotePropertyName "conditionalAccessPolicy" -NotePropertyValue $CAPolicy
$properties | Add-Member -NotePropertyName "guestAccess" -NotePropertyValue $guestAccess
# Return
$properties
}
}
}
# Gets Azure Tenant authentication methods
# Jun 30th 2020
function Get-TenantAuthenticationMethods
{
<#
.SYNOPSIS
Gets Azure tenant authentication methods.
.DESCRIPTION
Gets Azure tenant authentication methods.
.Example
Get-AADIntAccessTokenForAADIAMAPI
Tenant User Resource Client
------ ---- -------- ------
6e3846ee-e8ca-4609-a3ab-f405cfbd02cd 74658136-14ec-4630-ad9b-26e160ff0fc6 d3590ed6-52b3-4102-aeff-aad2292ab01c
PS C:\>Get-AADIntTenantAuthenticationMethods
id : 297c50d5-e789-40f7-8931-b3694713cb4d
type : 6
state : 0
includeConditions : {@{type=group; id=9202b94b-5381-4270-a3cb-7fcf0d40fef1; isRequired=False; useForSignIn=True}}
voiceSettings :
fidoSettings : @{allowSelfServiceSetup=False; enforceAttestation=False; keyRestrictions=}
enabled : True
method : FIDO2 Security Key
id : 3d2c4b8f-f362-4ce4-8f4b-cc8726b80106
type : 8
state : 1
includeConditions : {@{type=group; id=all_users; isRequired=False; useForSignIn=True}}
voiceSettings :
fidoSettings :
enabled : False
method : Microsoft Authenticator passwordless sign-in
id : d7716fe0-7c2e-4b52-a5cd-394f8999176b
type : 5
state : 1
includeConditions : {@{type=group; id=all_users; isRequired=False; useForSignIn=True}}
voiceSettings :
fidoSettings :
enabled : False
method : Text message
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
# Get from cache
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c"
# Get the authentication methods
$response = Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "AuthenticationMethods/AuthenticationMethodsPolicy"
$methods = $response.authenticationMethods
foreach($method in $methods)
{
$strType="unknown"
switch($method.type)
{
6 {$strType = "FIDO2 Security Key"}
8 {$strType = "Microsoft Authenticator passwordless sign-in"}
5 {$strType = "Text message"}
}
$method | Add-Member -NotePropertyName "enabled" -NotePropertyValue ($method.state -eq 0)
$method | Add-Member -NotePropertyName "method" -NotePropertyValue $strType
}
return $methods
}
}
# Gets Azure Tenant applications
# Nov 11th 2020
function Get-TenantApplications
{
<#
.SYNOPSIS
Gets Azure tenant applications.
.DESCRIPTION
Gets Azure tenant applications.
.Example
Get-AADIntAccessTokenForAADIAMAPI -SaveToCache
Tenant User Resource Client
------ ---- -------- ------
6e3846ee-e8ca-4609-a3ab-f405cfbd02cd https://management.core.windows.net/ d3590ed6-52b3-4102-aeff-aad2292ab01c
PS C:\>Get-AADIntTenantApplications
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
# Get from cache
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c"
$body = @{
"accountEnabled" = $null
"isAppVisible" = $null
"appListQuery"= 0
"top" = 999
"loadLogo" = $false
"putCachedLogoUrlOnly" = $true
"nextLink" = ""
"usedFirstPartyAppIds" = $null
"__ko_mapping__" = @{
"ignore" = @()
"include" = @("_destroy")
"copy" = @()
"observe" = @()
"mappedProperties" = @{
"accountEnabled" = $true
"isAppVisible" = $true
"appListQuery" = $true
"searchText" = $true
"top" = $true
"loadLogo" = $true
"putCachedLogoUrlOnly" = $true
"nextLink" = $true
"usedFirstPartyAppIds" = $true
}
"copiedProperties" = @{}
}
}
# Get the applications
$response = Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "ManagedApplications/List" -Body $body -Method Post
return $response.appList
}
}
# Get the status of AAD Connect
# Jan 7th 2021
function Get-AADConnectStatus
{
<#
.SYNOPSIS
Shows the status of Azure AD Connect (AAD Connect).
.DESCRIPTION
Shows the status of Azure AD Connect (AAD Connect).
.Example
Get-AADIntAccessTokenForAADIAMAPI -SaveToCache
PS C:\>Get-AADIntAADConnectStatus
verifiedDomainCount : 4
verifiedCustomDomainCount : 3
federatedDomainCount : 2
numberOfHoursFromLastSync : 0
dirSyncEnabled : True
dirSyncConfigured : True
passThroughAuthenticationEnabled : True
seamlessSingleSignOnEnabled : True
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
$AccessToken
)
Process
{
# Get from cache
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c"
# Get the applications
$response = Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "Directories/ADConnectStatus"
return $response
}
}
# Adds a new .onmicrosoft.com domain to the tenant
# Nov 11th 2022
function New-MOERADomain
{
<#
.SYNOPSIS
Adds a new Microsoft Online Email Routing Address (MOERA) domain (.onmicrosoft.com) to the tenant.
.DESCRIPTION
Adds a new Microsoft Online Email Routing Address (MOERA) domain (.onmicrosoft.com) to the tenant.
You can have add up to 30 MOERA domains, and can also add subdomains.
.Example
Get-AADIntAccessTokenForAADIAMAPI -SaveToCache
Tenant User Resource Client
------ ---- -------- ------
6e3846ee-e8ca-4609-a3ab-f405cfbd02cd 74658136-14ec-4630-ad9b-26e160ff0fc6 d3590ed6-52b3-4102-aeff-aad2292ab01c
PS C:\>New-AADIntMOERADomain -Domain "mydomain.onmicrosoft.com"
authenticationType :
isDefault : False
isInitial : False
isVerified : True
name : mydomain.onmicrosoft.com
forceDeleteState :
.Example
Get-AADIntAccessTokenForAADIAMAPI -SaveToCache
Tenant User Resource Client
------ ---- -------- ------
6e3846ee-e8ca-4609-a3ab-f405cfbd02cd 74658136-14ec-4630-ad9b-26e160ff0fc6 d3590ed6-52b3-4102-aeff-aad2292ab01c
PS C:\>New-AADIntMOERADomain -Domain "microsoft.onmicrosoft.com"
New-AADIntMOERADomain : Domain microsoft.onmicrosoft.com is already occupied by tenant 72f988bf-86f1-41af-91ab-2d7cd011db47
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$True)]
[String]$Domain
)
Process
{
# Get from cache
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -ClientId "d3590ed6-52b3-4102-aeff-aad2292ab01c"
# Check whether the domain already exist.
$tenantId = Get-TenantID -Domain $Domain
if($tenantId)
{
Write-Error "Domain $domain is already occupied by tenant $tenantId"
return
}
# Create the body
$body = @{"name" = $Domain}
# Add a new MOERA domain
try
{
$response = Call-AzureAADIAMAPI -AccessToken $AccessToken -Command "MoeraDomain" -Body $body -Method "Post"
}
catch
{
if($_.ErrorDetails.Message)
{
$message = $_.ErrorDetails.Message | ConvertFrom-Json
throw "$($message.Message) FaultType: $($message.ClientData.exceptionType)"
}
else
{
throw $_.Exception
}
}
return $response
}
}