-
Notifications
You must be signed in to change notification settings - Fork 218
/
GraphAPI.ps1
1014 lines (864 loc) · 35.1 KB
/
GraphAPI.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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This script contains functions for Graph API at https://graph.windows.net
# Office 365 / Azure AD v2, a.k.a. AzureAD module uses this API
function Get-DynamicAbusableGroups
{
<#
.SYNOPSIS
Return Entra ID groups with dynamic membership rule that contains attributes that can be modified by users.
Related articles:
https://medium.com/r3d-buck3t/abusing-dynamic-groups-in-azuread-part-1-ff12e328c8c0
https://www.mnemonic.io/resources/blog/abusing-dynamic-groups-in-azure-ad-for-privilege-escalation/
.DESCRIPTION
Return Entra ID groups with dynamic membership rule that contains attributes that can be modified by users using the given Access Token
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Get-AADIntDynamicAbusableGroups
abusableRule groupId
------------ -------
(user.userType -eq "Member") -or (user.city -eq "Redmond") 69d8fc52-d45e-47a2-972a-6c99e057ead1
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
$abusableCondsUser = @("ageGroup","jobTitle","city","givenName","displayName","companyName", "country","department","employeeType","mailNickname","mail","state")
$results=Call-GraphAPI -AccessToken $AccessToken -Command groups
$dynamicGroups = $results | Where-Object groupTypes -contains "DynamicMembership"
$userReg = 'user\.(.+?)\s'
$abusableGroupsOutput = @{}
foreach($dynamicGroup in $dynamicGroups){
$abusable = $false
$groupId = $dynamicGroup.objectId
$groupTempList = @()
$userMatches = $dynamicGroup.membershipRule | Select-String -Pattern $userReg -AllMatches
foreach($userMatch in $userMatches.Matches)
{
$matchType = $userMatch.Groups[1]
if($abusableCondsUser.Contains($matchType.value))
{
$abusable = $true
}
}
if($abusable)
{
$abusableGroupsOutput.Add($groupId,$dynamicGroup.membershipRule)
}
}
$abusableGroupsOutput.keys | % {
New-object psobject -Property @{
'groupId' = $_
'abusableRule' = $abusableGroupsOutput[$_]
}
}
return $abusableGroupsOutput
}
}
function Get-AADUsers
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$False)]
[String]$SearchString,
[Parameter(Mandatory=$False)]
[String]$UserPrincipalName
)
Process
{
if(![string]::IsNullOrEmpty($SearchString))
{
$queryString="`$filter=(startswith(displayName,'$SearchString') or startswith(userPrincipalName,'$SearchString'))"
}
elseif(![string]::IsNullOrEmpty($UserPrincipalName))
{
$queryString="`$filter=userPrincipalName eq '$UserPrincipalName'"
}
$results=Call-GraphAPI -AccessToken $AccessToken -Command users -QueryString $queryString
return $results
}
}
# Gets the tenant details
function Get-TenantDetails
{
<#
.SYNOPSIS
Extract tenant details using the given Access Token
.DESCRIPTION
Extract tenant details using the given Access Token
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>$token=Get-AADIntAccessTokenForAADGraph
PS C:\>Get-AADIntTenantDetails -AccessToken $token
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# Call the API
$response=Call-GraphAPI -AccessToken $AccessToken -Command tenantDetails
# Verbose
Write-Verbose "TENANT INFORMATION: $($response.value | Out-String)"
# Return
$response
}
}
# Gets the tenant devices
# Jun 24th 2020
function Get-Devices
{
<#
.SYNOPSIS
Extracts tenant devices using the given Access Token
.DESCRIPTION
Extracts tenant devices using the given Access Token
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>$token=Get-AADIntAccessTokenForAADGraph
PS C:\>Get-AADIntDevices -AccessToken $token
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# Call the API
$response=Call-GraphAPI -AccessToken $AccessToken -Command devices -QueryString "`$expand=registeredOwner"
# Return
$response
}
}
# Gets detailed information about the given user
# Jun 24th 2020
function Get-UserDetails
{
<#
.SYNOPSIS
Extracts detailed information of the given user
.DESCRIPTION
Extracts detailed information of the given user
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Parameter UserPrincipalName
The user principal name of the user whose details is to be extracted
.Example
PS C:\>$token=Get-AADIntAccessTokenForAADGraph
PS C:\>Get-AADIntUserDetails -AccessToken $token
odata.type : Microsoft.DirectoryServices.User
objectType : User
objectId : cd5676ad-ba80-4782-bdcb-ff5de37fc347
deletionTimestamp :
acceptedAs :
acceptedOn :
accountEnabled : True
ageGroup :
alternativeSecurityIds : {}
signInNames : {user@company.com}
signInNamesInfo : {}
appMetadata :
assignedLicenses : {@{disabledPlans=System.Object[]; skuId=c7df2760-2c81-4ef7-b578-5b5392b571df}, @{disabledPlans=System.Object[]; skuId=b05e124f-c7cc-45a0-a6aa-8cf78c946968}}
assignedPlans : {@{assignedTimestamp=2019-12-02T07:41:59Z; capabilityStatus=Enabled; service=MultiFactorService; servicePlanId=8a256a2b-b617-496d-b51b-e76466e88db0}, @{assignedTimestamp=2019-12-02T07
:41:59Z; capabilityStatus=Enabled; service=exchange; servicePlanId=34c0d7a0-a70f-4668-9238-47f9fc208882}, @{assignedTimestamp=2019-12-02T07:41:59Z; capabilityStatus=Enabled; service=P
owerBI; servicePlanId=70d33638-9c74-4d01-bfd3-562de28bd4ba}, @{assignedTimestamp=2019-12-02T07:41:59Z; capabilityStatus=Enabled; service=WhiteboardServices; servicePlanId=4a51bca5-1ef
f-43f5-878c-177680f191af}...}
city :
cloudAudioConferencingProviderInfo : <acpList>
<acpInformation default="true">
<tollNumber>18728886261</tollNumber>
<participantPassCode>0</participantPassCode>
<domain>resources.lync.com</domain>
<name>Microsoft</name>
<url>https://dialin.lync.com/c73270cd-afd0-4f70-8328-747f36508d85</url>
</acpInformation>
</acpList>
cloudMSExchRecipientDisplayType : 1073741824
cloudMSRtcIsSipEnabled : True
cloudMSRtcOwnerUrn :
...
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$True)]
[String]$UserPrincipalName
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# Url encode for external users, replace # with %23
$UserPrincipalName = $UserPrincipalName.Replace("#","%23")
# Call the API
$response=Call-GraphAPI -AccessToken $AccessToken -Command "users/$UserPrincipalName"
# Return
$response
}
}
# Gets tenant's Azure AD settings
# Jun 24th 2020
function Get-Settings
{
<#
.SYNOPSIS
Extracts Azure AD settings
.DESCRIPTION
Extracts Azure AD settings
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>$token=Get-AADIntAccessTokenForAADGraph
PS C:\>Get-AADIntSettings -AccessToken $token
id displayName templateId values
-- ----------- ---------- ------
8b16b029-bb31-48c8-b4df-5ee419596688 Password Rule Settings 5cf42378-d67d-4f36-ba46-e8b86229381d {@{name=BannedPasswordCheckOnPremisesMode; value=Audit}, @{name=EnableBannedPasswordCheckOnPremises; value=True}, @{name=En...
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# Call the API
$response=Call-GraphAPI -AccessToken $AccessToken -Command "settings"
# Return
$response
}
}
# Gets tenant's OAuth grants
# Jun 24th 2020
function Get-OAuthGrants
{
<#
.SYNOPSIS
Extracts Azure AD OAuth grants
.DESCRIPTION
Extracts Azure AD OAuth grants
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>$token=Get-AADIntAccessTokenForAADGraph
PS C:\>Get-AADIntOAuthGrants -AccessToken $token
id displayName templateId values
-- ----------- ---------- ------
8b16b029-bb31-48c8-b4df-5ee419596688 Password Rule Settings 5cf42378-d67d-4f36-ba46-e8b86229381d {@{name=BannedPasswordCheckOnPremisesMode; value=Audit}, @{name=EnableBannedPasswordCheckOnPremises; value=True}, @{name=En...
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# Call the API
$response=Call-GraphAPI -AccessToken $AccessToken -Command "oauth2PermissionGrants"
# Return
$response
}
}
# Gets tenant's service principals
# Jun 24th 2020
function Get-ServicePrincipals
{
<#
.SYNOPSIS
Extracts Azure AD service principals
.DESCRIPTION
Extracts Azure AD service principals. If client id(s) are provided, show detailed information.
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Parameter ClientIds
List of client ids to get detailed information.
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Get-AADIntServicePrincipals
AccountEnabled : true
Addresses :
AppPrincipalId : d32c68ad-72d2-4acb-a0c7-46bb2cf93873
DisplayName : Microsoft Activity Feed Service
ObjectId : 321e7bdd-d7b0-4a64-8eb3-38c259c1304a
ServicePrincipalNames : ServicePrincipalNames
TrustedForDelegation : false
AccountEnabled : true
Addresses : Addresses
AppPrincipalId : 0000000c-0000-0000-c000-000000000000
DisplayName : Microsoft App Access Panel
ObjectId : a9e03f2f-4471-41f2-96c5-589d5d7117bc
ServicePrincipalNames : ServicePrincipalNames
TrustedForDelegation : false
AccountEnabled : true
Addresses :
AppPrincipalId : dee7ba80-6a55-4f3b-a86c-746a9231ae49
DisplayName : Microsoft AppPlat EMA
ObjectId : ae0b81fc-c521-4bfd-9eaa-04c520b4b5fd
ServicePrincipalNames : ServicePrincipalNames
TrustedForDelegation : false
AccountEnabled : true
Addresses : Addresses
AppPrincipalId : 65d91a3d-ab74-42e6-8a2f-0add61688c74
DisplayName : Microsoft Approval Management
ObjectId : d8ec5b95-e5f6-416e-8e7c-c6c52ec5a11f
ServicePrincipalNames : ServicePrincipalNames
TrustedForDelegation : false
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$False)]
[String[]]$ClientIds
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# If client id(s) are provided, get only those (with extra information)
if($ClientIds)
{
$body = @{
"appIds" = $ClientIds
}
# Call the API
Call-GraphAPI -AccessToken $AccessToken -Command "getServicePrincipalsByAppIds" -Body ($body | ConvertTo-Json) -Method Post -QueryString "`$Select="
}
else
{
# Call the Provisioning API
Get-ServicePrincipals2 -AccessToken $AccessToken
}
}
}
# Gets tenant's conditional access policies
# Apr 8th 2021
function Get-ConditionalAccessPolicies
{
<#
.SYNOPSIS
Shows conditional access policies.
.DESCRIPTION
Shows conditional access policies.
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Get-AADIntConditionalAccessPolicies
odata.type : Microsoft.DirectoryServices.Policy
objectType : Policy
objectId : 1a6a3b84-7d6d-4398-9c26-50fab315be8b
deletionTimestamp :
displayName : Default Policy
keyCredentials : {}
policyType : 18
policyDetail : {{"Version":0,"State":"Disabled"}}
policyIdentifier : 2022-11-18T00:16:20.2379877Z
tenantDefaultPolicy : 18
odata.type : Microsoft.DirectoryServices.Policy
objectType : Policy
objectId : 7f6ac8e5-bd21-4091-ae4c-0e48e0f4db04
deletionTimestamp :
displayName : Block NestorW
keyCredentials : {}
policyType : 18
policyDetail : {{"Version":1,"CreatedDateTime":"2022-11-18T00:16:19.461967Z","State":"Enabled
","Conditions":{"Applications":{"Include":[{"Applications":["None"]}]},"Users"
:{"Include":[{"Users":["8ab3ed0d-6668-49f7-a108-c50bb230c870"]}]}},"Controls":
[{"Control":["Block"]}],"EnforceAllPoliciesForEas":true,"IncludeOtherLegacyCli
entTypeForEvaluation":true}}
policyIdentifier :
tenantDefaultPolicy :
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
# Return conditional access policies
Get-AzureADPolicies -AccessToken $AccessToken | Where policyType -eq 18
}
}
# Gets tenant's Azure AD Policies
# Nov 17th 2022
function Get-AzureADPolicies
{
<#
.SYNOPSIS
Shows Azure AD policies.
.DESCRIPTION
Shows Azure AD policies.
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Get-AADIntAzureADPolicies
odata.type : Microsoft.DirectoryServices.Policy
objectType : Policy
objectId : e35e4cd3-53f8-4d65-80bb-e3279c2c1b71
deletionTimestamp :
displayName : On-Premise Authentication Flow Policy
keyCredentials : {**}
policyType : 8
policyDetail : {**}
policyIdentifier :
tenantDefaultPolicy : 8
odata.type : Microsoft.DirectoryServices.Policy
objectType : Policy
objectId : 259b810f-fb50-4e57-925b-ec2292c17883
deletionTimestamp :
displayName : 2/5/2021 5:53:07 AM
keyCredentials : {}
policyType : 10
policyDetail : {{"SecurityPolicy":{"Version":0,"SecurityDefaults":{"IgnoreBaselineProtectionPolicies":true,"I
sEnabled":false}}}}
policyIdentifier :
tenantDefaultPolicy : 10
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
# Call the API
Call-GraphAPI -AccessToken $AccessToken -Command "policies" -Method Get
}
}
# Gets tenant's Azure AD Policies
# Nov 17th 2022
function Set-AzureADPolicyDetails
{
<#
.SYNOPSIS
Sets Azure AD policy details.
.DESCRIPTION
Sets Azure AD policy details.
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.PARAMETER ObjectId
Object ID of the policy
.PARAMETER PolicyDetail
Policy details.
.PARAMETER DisplayName
New displayname of the policy
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Set-AADIntAzureADPolicyDetail -ObjectId "e35e4cd3-53f8-4d65-80bb-e3279c2c1b71" -PolicyDetail '{{"SecurityPolicy":{"Version":0,"SecurityDefaults":{"IgnoreBaselineProtectionPolicies":true,"IsEnabled":false}}}}'
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Set-AADIntAzureADPolicyDetail -ObjectId "e35e4cd3-53f8-4d65-80bb-e3279c2c1b71" -PolicyDetail '{{"SecurityPolicy":{"Version":0,"SecurityDefaults":{"IgnoreBaselineProtectionPolicies":true,"IsEnabled":false}}}}' -displayName "My Policy"
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$True)]
[Guid]$ObjectId,
[Parameter(Mandatory=$True)]
[String]$PolicyDetail,
[Parameter(Mandatory=$False)]
[String]$DisplayName
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
$body = @{
"policyDetail" = @($PolicyDetail)
}
if(![string]::IsNullOrEmpty($DisplayName))
{
$body["displayName"] = $DisplayName
}
# Call the API
Call-GraphAPI -AccessToken $AccessToken -Command "policies/$($ObjectId)" -Method Patch -Body ($body | ConvertTo-Json)
}
}
# Get Azure AD features
# Aug 23 2023
function Get-AzureADFeatures
{
<#
.SYNOPSIS
Show the status of Azure AD features.
.DESCRIPTION
Show the status of Azure AD features using Azure AD Graph internal API.
Requires Global Administrator role
.Parameter AccessToken
Access Token
.Example
Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Get-AADIntAzureADFeatures
Feature Enabled
------- -------
AllowEmailVerifiedUsers True
AllowInvitations True
AllowMemberUsersToInviteOthersAsMembers False
AllowUsersToChangeTheirDisplayName False
B2CFeature False
BlockAllTenantAuth False
ConsentedForMigrationToPublicCloud False
CIAMFeature False
CIAMTrialFeature False
CIAMTrialUpgrade False
EnableExchangeDualWrite False
EnableHiddenMembership False
EnableSharedEmailDomainApis False
EnableWindowsLegacyCredentials False
EnableWindowsSupplementalCredentials False
ElevatedGuestsAccessEnabled False
ExchangeDualWriteUsersV1 False
GuestsCanInviteOthersEnabled True
InvitationsEnabled True
LargeScaleTenant False
TestTenant False
USGovTenant False
DisableOnPremisesWindowsLegacyCredentialsSync False
DisableOnPremisesWindowsSupplementalCredentialsSync False
RestrictPublicNetworkAccess False
AutoApproveSameTenantRequests False
RedirectPpeUsersToMsaInt False
LegacyTlsExceptionForEsts False
LegacyTlsBlockForEsts False
TenantAuthBlockReasonFraud False
TenantAuthBlockReasonLifecycle False
TenantExcludeDeprecateAADLicenses False
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Begin
{
$features = @(
"AllowEmailVerifiedUsers"
"AllowInvitations"
"AllowMemberUsersToInviteOthersAsMembers"
"AllowUsersToChangeTheirDisplayName"
"B2CFeature"
"BlockAllTenantAuth"
"ConsentedForMigrationToPublicCloud"
"CIAMFeature"
"CIAMTrialFeature"
"CIAMTrialUpgrade"
"EnableExchangeDualWrite"
"EnableHiddenMembership"
"EnableSharedEmailDomainApis"
"EnableWindowsLegacyCredentials"
"EnableWindowsSupplementalCredentials"
"ElevatedGuestsAccessEnabled"
"ExchangeDualWriteUsersV1"
"GuestsCanInviteOthersEnabled"
"InvitationsEnabled"
"LargeScaleTenant"
"TestTenant"
"USGovTenant"
"DisableOnPremisesWindowsLegacyCredentialsSync"
"DisableOnPremisesWindowsSupplementalCredentialsSync"
"RestrictPublicNetworkAccess"
"AutoApproveSameTenantRequests"
"RedirectPpeUsersToMsaInt"
"LegacyTlsExceptionForEsts"
"LegacyTlsBlockForEsts"
"TenantAuthBlockReasonFraud"
"TenantAuthBlockReasonLifecycle"
"TenantExcludeDeprecateAADLicenses"
)
}
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
$retVal = @()
# Loop through the features
foreach($feature in $features)
{
try
{
$value = Get-AzureADFeature -AccessToken $AccessToken -Feature $feature
$retVal += [pscustomobject][ordered]@{
"Feature" = $feature
"Enabled" = $value
}
}
catch
{
}
}
$retVal
}
}
# Get Azure AD feature status
# Aug 23 2023
function Get-AzureADFeature
{
<#
.SYNOPSIS
Show the status of given Azure AD feature.
.DESCRIPTION
Show the status of given Azure AD feature using Azure AD Graph internal API.
Requires Global Administrator role
.Parameter AccessToken
Access Token
.PARAMETER Feature
The name of the feature. Should be one of:
AllowEmailVerifiedUsers
AllowInvitations
AllowMemberUsersToInviteOthersAsMembers
AllowUsersToChangeTheirDisplayName
B2CFeature
BlockAllTenantAuth
ConsentedForMigrationToPublicCloud
CIAMFeature
CIAMTrialFeature
CIAMTrialUpgrade
EnableExchangeDualWrite
EnableHiddenMembership
EnableSharedEmailDomainApis
EnableWindowsLegacyCredentials
EnableWindowsSupplementalCredentials
ElevatedGuestsAccessEnabled
ExchangeDualWriteUsersV1
GuestsCanInviteOthersEnabled
InvitationsEnabled
LargeScaleTenant
TestTenant
USGovTenant
DisableOnPremisesWindowsLegacyCredentialsSync
DisableOnPremisesWindowsSupplementalCredentialsSync
RestrictPublicNetworkAccess
AutoApproveSameTenantRequests
RedirectPpeUsersToMsaInt
LegacyTlsExceptionForEsts
LegacyTlsBlockForEsts
TenantAuthBlockReasonFraud
TenantAuthBlockReasonLifecycle
TenantExcludeDeprecateAADLicenses
.Example
Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Get-AADIntAzureADFeature -Feature "B2CFeature"
True
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[ValidateSet('AllowEmailVerifiedUsers','AllowInvitations','AllowMemberUsersToInviteOthersAsMembers','AllowUsersToChangeTheirDisplayName','B2CFeature','BlockAllTenantAuth','ConsentedForMigrationToPublicCloud','CIAMFeature','CIAMTrialFeature','CIAMTrialUpgrade','EnableExchangeDualWrite','EnableHiddenMembership','EnableSharedEmailDomainApis','EnableWindowsLegacyCredentials','EnableWindowsSupplementalCredentials','ElevatedGuestsAccessEnabled','ExchangeDualWriteUsersV1','GuestsCanInviteOthersEnabled','InvitationsEnabled','LargeScaleTenant','TestTenant','USGovTenant','DisableOnPremisesWindowsLegacyCredentialsSync','DisableOnPremisesWindowsSupplementalCredentialsSync','RestrictPublicNetworkAccess','AutoApproveSameTenantRequests','RedirectPpeUsersToMsaInt','LegacyTlsExceptionForEsts','LegacyTlsBlockForEsts','TenantAuthBlockReasonFraud','TenantAuthBlockReasonLifecycle','TenantExcludeDeprecateAADLicenses')]
[Parameter(Mandatory=$True)]
[String]$Feature
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
$body = @{
"directoryFeature" = $feature
}
# Call the API
try
{
$response = Call-GraphAPI -AccessToken $AccessToken -Command "isDirectoryFeatureEnabled" -Method Post -Body ($body | ConvertTo-Json)
$enabled = $false;
# For some reason True is returned as boolean but False as object with value attribute
if($response -isnot [boolean])
{
$enabled = $response.Value
}
else
{
$enabled = $response
}
return $enabled
}
catch
{
$stream = $_.Exception.Response.GetResponseStream()
$responseBytes = New-Object byte[] $stream.Length
$stream.Position = 0
$stream.Read($responseBytes,0,$stream.Length) | Out-Null
$response = [text.encoding]::UTF8.GetString($responseBytes) | ConvertFrom-Json
throw $response.'odata.error'.message.value
}
}
}
# Enable or Disable Azure AD feature
# Aug 23 2023
function Set-AzureADFeature
{
<#
.SYNOPSIS
Enables or disables the given Azure AD feature.
.DESCRIPTION
Enables or disables the given Azure AD feature using Azure AD Graph internal API.
Requires Global Administrator role
.Parameter AccessToken
Access Token
.PARAMETER Feature
The name of the feature. Should be one of:
AllowEmailVerifiedUsers
AllowInvitations
AllowMemberUsersToInviteOthersAsMembers
AllowUsersToChangeTheirDisplayName
B2CFeature
BlockAllTenantAuth
ConsentedForMigrationToPublicCloud
CIAMFeature
CIAMTrialFeature
CIAMTrialUpgrade
EnableExchangeDualWrite
EnableHiddenMembership
EnableSharedEmailDomainApis
EnableWindowsLegacyCredentials
EnableWindowsSupplementalCredentials
ElevatedGuestsAccessEnabled
ExchangeDualWriteUsersV1
GuestsCanInviteOthersEnabled
InvitationsEnabled
LargeScaleTenant
TestTenant
USGovTenant
DisableOnPremisesWindowsLegacyCredentialsSync
DisableOnPremisesWindowsSupplementalCredentialsSync
RestrictPublicNetworkAccess
AutoApproveSameTenantRequests
RedirectPpeUsersToMsaInt
LegacyTlsExceptionForEsts
LegacyTlsBlockForEsts
TenantAuthBlockReasonFraud
TenantAuthBlockReasonLifecycle
TenantExcludeDeprecateAADLicenses
.Example
Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Set-AADIntAzureADFeature -Feature "B2CFeature" -Enable $true
Feature Enabled
------- -------
B2CFeature True
.Example
Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Set-AADIntAzureADFeature -Feature "B2CFeature" -Enable $false
Feature Enabled
------- -------
B2CFeature False
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[ValidateSet('AllowEmailVerifiedUsers','AllowInvitations','AllowMemberUsersToInviteOthersAsMembers','AllowUsersToChangeTheirDisplayName','B2CFeature','BlockAllTenantAuth','ConsentedForMigrationToPublicCloud','CIAMFeature','CIAMTrialFeature','CIAMTrialUpgrade','EnableExchangeDualWrite','EnableHiddenMembership','EnableSharedEmailDomainApis','EnableWindowsLegacyCredentials','EnableWindowsSupplementalCredentials','ElevatedGuestsAccessEnabled','ExchangeDualWriteUsersV1','GuestsCanInviteOthersEnabled','InvitationsEnabled','LargeScaleTenant','TestTenant','USGovTenant','DisableOnPremisesWindowsLegacyCredentialsSync','DisableOnPremisesWindowsSupplementalCredentialsSync','RestrictPublicNetworkAccess','AutoApproveSameTenantRequests','RedirectPpeUsersToMsaInt','LegacyTlsExceptionForEsts','LegacyTlsBlockForEsts','TenantAuthBlockReasonFraud','TenantAuthBlockReasonLifecycle','TenantExcludeDeprecateAADLicenses')]
[Parameter(Mandatory=$True)]
[String]$Feature,
[Parameter(Mandatory=$True)]
[bool]$Enabled
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
$isEnabled = Get-AzureADFeature -Feature $feature -AccessToken $AccessToken
if($Enabled)
{
# Check if already enabled
if($isEnabled)
{
Write-Warning "Feature $feature is already enabled."
return
}
$command = "enableDirectoryFeature"
}
else
{
# Check if already disabled
if(!$isEnabled)
{
Write-Warning "Feature $feature is already disabled."
return
}
$command = "disableDirectoryFeature"
}
$body = @{
"directoryFeature" = $feature
}
# Call the API
try
{
Call-GraphAPI -AccessToken $AccessToken -Command $command -Method Post -Body ($body | ConvertTo-Json)
}
catch
{
$stream = $_.Exception.Response.GetResponseStream()
$responseBytes = New-Object byte[] $stream.Length
$stream.Position = 0
$stream.Read($responseBytes,0,$stream.Length) | Out-Null
$response = [text.encoding]::UTF8.GetString($responseBytes) | ConvertFrom-Json
throw $response.'odata.error'.message.value
}
[pscustomobject][ordered]@{
"Feature" = $feature
"Enabled" = Get-AzureADFeature -AccessToken $AccessToken -Feature $feature
}
}
}
# Adds Microsoft.Azure.SyncFabric service principal
# Dec 4th 2023
function Add-SyncFabricServicePrincipal
{
<#
.SYNOPSIS
Adds Microsoft.Azure.SyncFabric service principal needed to create BPRTs.
.DESCRIPTION
Adds Microsoft.Azure.SyncFabric service principal needed to create BPRTs.
Requires Application Administrator, Cloud Application Administrator, Directory Synchronization Accounts, Hybrid Identity Administrator, or Global Administrator permissions.
.Parameter AccessToken
The Access Token. If not given, tries to use cached Access Token.
.Example
PS C:\>Get-AADIntAccessTokenForAADGraph -SaveToCache
PS C:\>Add-AADIntSyncFabricServicePrincipal
DisplayName AppId ObjectId
----------- ----- --------
Microsoft.Azure.SyncFabric 00000014-0000-0000-c000-000000000000 138018f7-6aa2-454c-a103-a7e682e17d6b
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -ClientID "1b730954-1685-4b74-9bfd-dac224a7b894" -Resource "https://graph.windows.net"
$body = @{
"accountEnabled" = "True"
"appId" = "00000014-0000-0000-c000-000000000000"
"appRoleAssignmentRequired" = $false
"displayName" = "Microsoft.Azure.SyncFabric"
"tags" = @( "WindowsAzureActiveDirectoryIntegratedApp" )
}
# Call the API