-
Notifications
You must be signed in to change notification settings - Fork 4
/
Get-AADRawData.ps1
193 lines (181 loc) · 9.77 KB
/
Get-AADRawData.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
<#
.NOTES
All rigts reserved to
Robert Przybylski
www.azureblog.pl
robert(at)azureblog.pl
2022
.Example
.\Get-AADRawData.ps1 -OutputPath $OutputPath -CliXMLPath CliXMLPath -SecretCliXMLPath SecretCliXMLPath -ApplicationID ApplicationID -CertificateThumbprint CertificateThumbprint -TenantID TenantID -TenatDomainName TenatDomainName
Working on URI 'https://graph.microsoft.com/v1.0/devices'
Working on URI 'https://graph.microsoft.com/v1.0/directoryRoles'
Working on URI 'https://graph.microsoft.com/v1.0/domains'
Working on URI 'https://graph.microsoft.com/v1.0/groupSettings'
Working on URI 'https://graph.microsoft.com/v1.0/users'
Working on URI 'https://graph.microsoft.com/v1.0/directoryRoles'
Working on URI 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies'
Working on URI 'https://graph.microsoft.com/v1.0/identityGovernance/accessReviews/definitions'
Working on URI 'https://graph.microsoft.com/v1.0/identityGovernance/entitlementManagement'
Working on URI 'https://graph.microsoft.com/v1.0/identityGovernance/termsOfUse/agreements'
Working on URI 'https://graph.microsoft.com/v1.0/authenticationMethodsPolicy'
Working on URI 'https://graph.microsoft.com/v1.0/policies/identitySecurityDefaultsEnforcementPolicy'
Working on URI 'https://graph.microsoft.com/v1.0/subscribedSkus'
Working on URI 'https://graph.microsoft.com/v1.0/security/secureScores'
Working on URI 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations'
Working on URI 'https://graph.microsoft.com/v1.0/directory/administrativeUnits'
Working on URI 'https://graph.microsoft.com/v1.0/authenticationMethodsPolicy'
Working on URI 'https://graph.microsoft.com/v1.0/policies/crossTenantAccessPolicy/partners'
Working on URI 'https://graph.microsoft.com/v1.0/policies/crossTenantAccessPolicy/default'
Working on URI 'https://graph.microsoft.com/v1.0/policies/adminConsentRequestPolicy'
.Example
VERBOSE: OutputPath: 'X:\temp\AAD_Audit\MVP Tenant\RAW'
VERBOSE: SecretCliXMLPath: 'XXXX\AppSecret.xml'
VERBOSE: ApplicationID: 'XXXX'
VERBOSE: TenantID: 'XXXX'
VERBOSE: TenantDomainName: 'mvp.azureblog.pl'
VERBOSE: DebugMe: ''
VERBOSE: POST with -1-byte payload
VERBOSE: received 2412-byte response of content type application/json; charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/devices'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/directoryRoles'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/domains'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/groupSettings'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/users'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/directoryRoles'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/identityGovernance/accessReviews/definitions'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/identityGovernance/entitlementManagement'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/identityGovernance/termsOfUse/agreements'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/authenticationMethodsPolicy'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/policies/identitySecurityDefaultsEnforcementPolicy'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/subscribedSkus'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/directory/administrativeUnits'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/authenticationMethodsPolicy'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type
application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/policies/crossTenantAccessPolicy/partners'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/policies/crossTenantAccessPolicy/default'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Working on URI 'https://graph.microsoft.com/v1.0/policies/adminConsentRequestPolicy'
VERBOSE: GET with 0-byte payload
VERBOSE: received -1-byte response of content type application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
#>
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[string] $OutputPath,
[Parameter(Position = 1)]
[string] $SecretCliXMLPath,
[Parameter(Position = 2)]
[string] $ApplicationID,
[Parameter(Position = 3)]
[string] $CertificateThumbprint,
[Parameter(Position = 4)]
[string] $TenantID,
[Parameter(Position = 5)]
[string] $TenantDomainName
)
Write-Verbose "OutputPath: '$OutputPath'"
Write-Verbose "SecretCliXMLPath: '$SecretCliXMLPath'"
Write-Verbose "ApplicationID: '$ApplicationID'"
Write-Verbose "TenantID: '$TenantID'"
Write-Verbose "TenantDomainName: '$TenantDomainName'"
Write-Verbose "DebugMe: '$DebugMe'"
$uriPrefix = 'https://graph.microsoft.com/v1.0/'
$uriArray = @(
"devices",
"directoryRoles",
"domains",
"groupSettings",
'users',
'directoryRoles',
"identity/conditionalAccess/policies",
"identityGovernance/accessReviews/definitions",
"identityGovernance/entitlementManagement",
"identityGovernance/termsOfUse/agreements",
"authenticationMethodsPolicy",
"policies/identitySecurityDefaultsEnforcementPolicy",
"subscribedSkus",
'identity/conditionalAccess/namedLocations',
'directory/administrativeUnits',
'authenticationMethodsPolicy',
'policies/crossTenantAccessPolicy/partners',
'policies/crossTenantAccessPolicy/default',
'policies/adminConsentRequestPolicy'
'/roleManagement/directory/roleEligibilityScheduleInstances'
)
try {
Get-AZTenant | out-null
}
catch {
Login-AzAccount -CertificateThumbprint $certificateThumbprint -ApplicationId $ApplicationID -TenantId $TenantID | Out-Null
}
#Region Connection
$Body = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
client_Id = $applicationID
Client_Secret = (Import-CliXml -Path $SecretCliXMLPath).GetNetworkCredential().Password
}
$connectGraph = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantDomainName/oauth2/v2.0/token" -Method POST -Body $Body -ContentType 'application/x-www-form-urlencoded'
$authHeader = @{
'Authorization' = "Bearer $($connectGraph.access_token)"
}
#endregion
foreach ($entry in $uriArray) {
$uri = $uriPrefix + $entry
Write-Host "Working on URI '$uri'" -ForegroundColor Yellow
$output = Invoke-RestMethod -Headers $authHeader -Uri $Uri -Method get | convertto-json -Depth 10
$outputFile = "$OutputPath\" + ($entry).replace('/', '').replace('?', '').replace('=', '').replace('$', '') + ".json"
$output | Out-file $outputFile
}