-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGet-IntuneUpdateRing.ps1
More file actions
185 lines (146 loc) · 7.08 KB
/
Copy pathGet-IntuneUpdateRing.ps1
File metadata and controls
185 lines (146 loc) · 7.08 KB
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
function Get-IntuneUpdateRing {
[CmdletBinding()]
param (
[Parameter()]
[String]$Ring,
[Parameter()]
[Switch]$Status,
[Parameter()]
[Switch]$All
)
<#
IMPORTANT:
===========================================================================
This script is provided 'as is' without any warranty. Any issues stemming
from use is on the user.
===========================================================================
.DESCRIPTION
Retrieves Intune Update Ring and status.
Things to change before using:
Line 69 - replace x with clientID of your reigstered app. See https://bit.ly/3KApKhJ for more info.
Line 140 - replace x with clientID of your reigstered app. See https://bit.ly/3KApKhJ for more info.
===========================================================================
.PARAMETER Ring
Name of the Update Ring to pull
Returns update status for the specified Update Ring.
===========================================================================
.EXAMPLE
Get-IntuneUpdateRing -Ring StandardUsers <--- This will retrieve details about the Update Ring itself
Get-IntuneUpdateRing -Ring StandardUsers -Status <--- This will retrieve update status for Update Ring devices
#>
###########################################################
function Get-IntuneDeviceConfiguration {
<#
IMPORTANT:
===========================================================================
This script is provided 'as is' without any warranty. Any issues stemming
from use is on the user.
===========================================================================
.DESCRIPTION
Retrieves Intune configuration policy.
===========================================================================
.PARAMETER Name
Required if not using All switch - Name of the configuration policy to retrieve.
.PARAMETER All
Retrieves all Intune configuration policies.
.PARAMETER Status
Returns device status for the specified configuration policy.
===========================================================================
.EXAMPLE
Get-IntuneConfigurationPolicy -Policy BlockAllUSB <--- Retrieves BlockAllUSB configuration policy
Get-IntuneConfigurationPolicy -Policy BlockAllUSB -Status <--- Retrieves BlockAllUSB compliance policy device status
#>
[CmdletBinding()]
param (
[Parameter()]
[String]$Name,
[Parameter()]
[Switch]$All,
[Parameter()]
[Switch]$Status
)
$token = Get-MsalToken -clientid x -tenantid organizations
$global:header = @{'Authorization' = $token.createauthorizationHeader();'ConsistencyLevel' = 'eventual'}
If ($All -and !$Name){
$Uri = "https://graph.microsoft.com/beta/devicemanagement/deviceConfigurations"
Try {
(Invoke-RestMethod -Uri $Uri -Headers $Header).value
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
}
elseif ($Name -and !$All -and !$Status){
$Uri = "https://graph.microsoft.com/beta/devicemanagement/deviceConfigurations?`$filter=displayName%20eq%20'$Name'"
Try {
(Invoke-RestMethod -Uri $Uri -Headers $Header).value
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
}
elseif ($Name -and !$All -and $Status){
$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations?`$filter=displayName%20eq%20'$Name'"
Try {
$ConfigurationPolicy = (Invoke-RestMethod -Uri $Uri -Headers $Header -Method GET).value
$ConfigurationPolicyId = $ConfigurationPolicy | select -expand id
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
Try {
$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations/$ConfigurationPolicyId/deviceStatuses"
(Invoke-RestMethod -Uri $Uri -Headers $Header).value | select id,deviceDisplayName,LastReportedDateTime,status,userPrincipalName
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
}
}
##########################################################
$token = Get-MsalToken -clientid x -tenantid organizations
$global:header = @{'Authorization' = $token.createauthorizationHeader();'ConsistencyLevel' = 'eventual'}
If ($Ring -and !$Status){
$UpdateRing = Get-IntuneDeviceConfiguration -All | where {$_.displayName -like "*$Ring*"}
$UpdateRingId = $UpdateRing.Id
$Uri = "https://graph.microsoft.com/v1.0/deviceManagement/deviceConfigurations/$UpdateRingId"
Try {
Invoke-RestMethod -Uri $Uri -Headers $Header -Method Get
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
}
elseif ($Ring -and $Status){
$UpdateRing = Get-IntuneDeviceConfiguration -All | where {$_.displayName -like "*$Ring*"}
$UpdateRingId = $UpdateRing.Id
$Uri = "https://graph.microsoft.com/v1.0/deviceManagement/deviceConfigurations/$UpdateRingId/deviceStatuses"
Try {
(Invoke-RestMethod -Uri $Uri -Headers $Header -Method Get).value
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
}
elseif ($All){
Get-IntuneDeviceConfiguration -All | where {$_.microsoftUpdateServiceAllowed -eq 'true'}
}
}