|
| 1 | +# I just found this old script that was horribly written and am slowly fixing it up. 😅 |
| 2 | + |
1 | 3 | <# |
2 | 4 | .SYNOPSIS |
3 | 5 | An experimental way to get the list of URLs used by Microsoft 365 services. |
|
36 | 38 | https://docs.microsoft.com/en-us/graph/deployments |
37 | 39 | #> |
38 | 40 |
|
39 | | -# $Guid = New-Guid |
40 | | -[Guid]$global:Guid = 'f31523fa-cb44-44e6-9a13-037a0643e282' |
| 41 | +[guid]$Guid = 'f31523fa-cb44-44e6-9a13-037a0643e282' |
41 | 42 |
|
42 | 43 | function Get-InstanceNames { |
43 | 44 | # Get a list of available cloud instance names (gov, foreign, worldwide, etc) using a GUID for the request. |
44 | 45 | $UriInstanceNames = "https://endpoints.office.com/version?clientrequestid=$Guid" |
45 | | - $global:InstanceNames = ( ( (Invoke-WebRequest -Uri $UriInstanceNames).Content ) | ConvertFrom-Json ).instance |
| 46 | + $InstanceNames = ( ( (Invoke-WebRequest -Uri $UriInstanceNames).Content ) | ConvertFrom-Json ).instance |
| 47 | + return $InstanceNames |
46 | 48 | } # End function Get-InstanceNames |
47 | 49 |
|
48 | | -Get-InstanceNames |
49 | | - |
50 | 50 | function Get-ServiceAreas { |
51 | 51 | # Get all service area names for a given instance. |
52 | 52 | [CmdletBinding()] |
53 | 53 | param ( |
54 | 54 | [Parameter(Mandatory = $true)] |
55 | 55 | [ArgumentCompleter({ |
56 | 56 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) |
57 | | - if (!($global:InstanceNames)) { |
| 57 | + if (!($InstanceNames)) { |
58 | 58 | Get-InstanceNames |
59 | 59 | } else { |
60 | | - Return $global:InstanceNames |
| 60 | + return $InstanceNames |
61 | 61 | } |
62 | 62 | })] |
63 | 63 | [string] |
64 | 64 | $Instance |
65 | 65 | ) |
66 | 66 |
|
67 | | - $Uri = "https://endpoints.office.com/endpoints/$Instance" + "?clientrequestid=$Guid" |
68 | | - $global:ServiceAreas = ( ( ((Invoke-WebRequest -Uri $Uri).Content) | ConvertFrom-Json ) | Select-Object serviceArea -Unique).servicearea |
69 | | - Return $global:ServiceAreas |
| 67 | + $Uri = "https://endpoints.office.com/endpoints/$Instance" + "?ClientRequestId=$Guid" |
| 68 | + $ServiceAreas = ( ( ((Invoke-WebRequest -Uri $Uri).Content) | ConvertFrom-Json ) | Select-Object serviceArea -Unique).ServiceArea |
| 69 | + return $ServiceAreas |
70 | 70 | } # End function Get-ServiceAreas |
71 | 71 |
|
72 | 72 | function Get-ServiceUrls { |
73 | 73 | # Get all service URLs for a selected instance and service area. |
74 | 74 | [CmdletBinding()] |
75 | 75 | param ( |
76 | | - [Parameter(Mandatory = $true)] |
| 76 | + [Parameter()] |
77 | 77 | [ArgumentCompleter({ |
78 | 78 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) |
79 | | - if (!($global:InstanceNames)) { |
| 79 | + if (!($InstanceNames)) { |
80 | 80 | Get-InstanceNames |
81 | 81 | } else { |
82 | | - Return $global:InstanceNames |
| 82 | + return $InstanceNames |
83 | 83 | } |
84 | 84 | })] |
85 | 85 | [string] |
86 | | - $Instance, |
| 86 | + $Instance = 'Worldwide', |
87 | 87 | [ArgumentCompleter( |
88 | 88 | { |
89 | 89 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) |
90 | | - if (!($global:InstanceNames)) { |
| 90 | + if (!($InstanceNames)) { |
91 | 91 | Get-InstanceTypes |
92 | 92 | } elseif (!($ServiceAreas)) { |
93 | 93 | if (!($Instance)) { |
94 | 94 | $Instance = 'Worldwide' |
95 | 95 | } |
96 | 96 | Get-ServiceAreas -InstanceName $Instance |
97 | 97 | } else { |
98 | | - Return $global:ServiceAreas |
| 98 | + return $ServiceAreas |
99 | 99 | } |
100 | 100 | } |
101 | 101 | )] |
102 | 102 | [string] |
103 | 103 | $ServiceArea |
104 | 104 | ) |
105 | 105 |
|
106 | | - $Uri = "https://endpoints.office.com/endpoints/$Instance" + "?clientrequestid=$Guid" + '&' + "serviceArea=$ServiceArea" |
107 | | - $global:ServiceUrls = ( ( ((Invoke-WebRequest -Uri $Uri).Content) | ConvertFrom-Json ) | Select-Object urls -Unique).urls |
108 | | - Return $global:ServiceUrls |
| 106 | + $Uri = "https://endpoints.office.com/endpoints/$Instance" + "?ClientRequestId=$Guid" + '&' + "serviceArea=$ServiceArea" |
| 107 | + $ServiceUrls = ( ( ((Invoke-WebRequest -Uri $Uri).Content) | ConvertFrom-Json ) | Select-Object urls -Unique).urls |
| 108 | + return $ServiceUrls |
109 | 109 | } |
110 | | - |
111 | | - |
112 | | -#region Appendix |
113 | | - |
114 | | -<# SCRATCH PAD |
115 | | - # Fun, but probably not necessary: |
116 | | - [Guid]$global:Guid = "f31523fa-cb44-44e6-9a13-037a0643e282" |
117 | | - $UriInstanceNames = "https://endpoints.office.com/version?clientrequestid=$Guid" |
118 | | - $global:InstanceNames = ( ( (Invoke-WebRequest -Uri $UriInstanceNames).Content ) | ConvertFrom-Json ).instance |
119 | | -
|
120 | | - foreach ($item in $InstanceNames) { |
121 | | - $VariableName = '$Endpoints'+"$item" |
122 | | - $Expression = "$Variablename = " + '"' + "https://endpoints.office.com/endpoints/"+"$item"+"?clientrequestid=$($Guid)" + '"' |
123 | | - Invoke-Expression $Expression |
124 | | - Write-Output `n"A new URI variable has been created for $item : " $Expression |
125 | | - } |
126 | | -
|
127 | | -#> |
128 | | - |
129 | | -# SAMPLE JSON DATA |
130 | | -<# SAMPLE INSTANCE OUTPUT |
131 | | - [ |
132 | | - { |
133 | | - "instance": "Worldwide", |
134 | | - "latest": "2021102900" |
135 | | - }, |
136 | | - { |
137 | | - "instance": "USGovDoD", |
138 | | - "latest": "2021102900" |
139 | | - }, |
140 | | - { |
141 | | - "instance": "USGovGCCHigh", |
142 | | - "latest": "2021102900" |
143 | | - }, |
144 | | - { |
145 | | - "instance": "China", |
146 | | - "latest": "2021092800" |
147 | | - }, |
148 | | - { |
149 | | - "instance": "Germany", |
150 | | - "latest": "2021102900" |
151 | | - } |
152 | | - ] |
153 | | -#> |
154 | | - |
155 | | -<# SAMPLE GCCHIGH OUTPUT |
156 | | - [ |
157 | | - { |
158 | | - "id": 1, |
159 | | - "serviceArea": "Exchange", |
160 | | - "serviceAreaDisplayName": "Exchange Online", |
161 | | - "urls": [ |
162 | | - "outlook.office365.us" |
163 | | - ], |
164 | | - "ips": [ |
165 | | - "20.35.208.0/20", |
166 | | - "20.35.240.0/21", |
167 | | - "40.66.16.0/21", |
168 | | - "131.253.83.0/26", |
169 | | - "131.253.84.64/26", |
170 | | - "131.253.84.192/26", |
171 | | - "131.253.86.0/24", |
172 | | - "131.253.87.144/28", |
173 | | - "131.253.87.208/28", |
174 | | - "131.253.87.240/28", |
175 | | - "131.253.88.0/28", |
176 | | - "131.253.88.32/28", |
177 | | - "131.253.88.48/28", |
178 | | - "131.253.88.96/28", |
179 | | - "131.253.88.128/28", |
180 | | - "131.253.88.144/28", |
181 | | - "131.253.88.160/28", |
182 | | - "131.253.88.192/28", |
183 | | - "131.253.88.240/28", |
184 | | - "2001:489a:2200:28::/62", |
185 | | - "2001:489a:2200:3c::/62", |
186 | | - "2001:489a:2200:44::/62", |
187 | | - "2001:489a:2200:58::/61", |
188 | | - "2001:489a:2200:60::/62", |
189 | | - "2001:489a:2200:79::/64", |
190 | | - "2001:489a:2200:7d::/64", |
191 | | - "2001:489a:2200:7f::/64", |
192 | | - "2001:489a:2200:80::/64", |
193 | | - "2001:489a:2200:82::/63", |
194 | | - "2001:489a:2200:86::/64", |
195 | | - "2001:489a:2200:88::/63", |
196 | | - "2001:489a:2200:8a::/64", |
197 | | - "2001:489a:2200:8c::/64", |
198 | | - "2001:489a:2200:8f::/64", |
199 | | - "2001:489a:2200:100::/56", |
200 | | - "2001:489a:2200:400::/56", |
201 | | - "2001:489a:2200:600::/56" |
202 | | - ], |
203 | | - "tcpPorts": "80,443", |
204 | | - "expressRoute": true, |
205 | | - "category": "Optimize", |
206 | | - "required": true |
207 | | - } |
208 | | - ] |
209 | | -#> |
210 | | - |
211 | | -#endregion Appendix |
0 commit comments