forked from iBowler1995/Functions-Intune-Graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-IntuneDevice.ps1
93 lines (67 loc) · 3.13 KB
/
Get-IntuneDevice.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
function Get-IntuneDevice {
<#
IMPORTANT:
===========================================================================
This script is provided 'as is' without any warranty. Any issues stemming
from use is on the user.
===========================================================================
.DESCRIPTION
Retrieves Intune managed device.
Things to change to deploy in your environment:
Line 34: replace x with clientID of your reigstered app. See https://docs.microsoft.com/en-us/graph/auth-v2-user for more info.
===========================================================================
.PARAMETER Name
Required if not using All switch - Name of the device to retrieve.
.PARAMETER All
Retrieves all Intune managed devices.
===========================================================================
.EXAMPLE
Assign-IntuneDevice -Name DESKTOP-7XH8Z <--- Retrieves DESKTOP-7XH8Z if exist
Assign-IntuneDevice -All <--- Retrieves all Intune managed devices.
#>
[CmdletBinding()]
param (
[Parameter()]
[String]$Name,
[Parameter()]
[Switch]$All
)
$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/managedDevices?`$filter=deviceName%20eq%20'$Name'"
Try {
$Device = (Invoke-RestMethod -Uri $Uri -Method Get -Headers $Header).value
If ($Device -ne $Null) {
$device
}
else {
Write-Host "Device $Name not found." -f Red
}
}
catch{
$ResponseResult = $_.Exception.Response.GetResponseStream()
$ResponseReader = New-Object System.IO.StreamReader($ResponseResult)
$ResponseBody = $ResponseReader.ReadToEnd()
$ResponseBody
}
}
elseif (!$All -and !$Name){
Write-Host "Please specify a device using the -Name parameter or use the -All switch to see all devices." -f Red
}
elseif ($All -and !$Name){
$Uri = "https://graph.microsoft.com/beta/deviceManagement/managedDevices?`$filter=(((deviceType%20eq%20%27desktop%27)%20or%20(deviceType%20eq%20%27windowsRT%27)%20or%20(deviceType%20eq%20%27winEmbedded%27)%20or%20(deviceType%20eq%20%27surfaceHub%27)))"
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
}
}
else{
Write-Host "Please specify a device using the -Name parameter or use the -All switch to see all devices." -f Red
}
}