-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathChange-DeviceCategory.ps1
More file actions
42 lines (36 loc) · 1.37 KB
/
Change-DeviceCategory.ps1
File metadata and controls
42 lines (36 loc) · 1.37 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
<#
.SYNOPSIS
Change the device category of an Intune managed device.
.DESCRIPTION
Sets the device category for a single Intune device using the Microsoft
Graph beta endpoint via the Intune PowerShell SDK (Connect-MSGraph).
.NOTES
Author : Jannik Reinhard (jannikreinhard.com)
Version: 1.1
Release: v1.0 - Init
v1.1 - Renamed function to Set-DeviceCategory, added validation
#>
# NOTE: Connect-MSGraph is part of the deprecated Intune PowerShell SDK.
# Consider migrating to Microsoft.Graph module with Connect-MgGraph.
Connect-MSGraph
Update-MSGraphEnvironment -SchemaVersion 'beta'
function Set-DeviceCategory {
param(
[Parameter(Mandatory)]
[ValidateScript({ $_ -ne 'ADD-DEVICE-ID' })]
[string]$DeviceID,
[Parameter(Mandatory)]
[ValidateScript({ $_ -ne 'ADD-THE-DEVICE-CATEGORY-ID' })]
[string]$DeviceCategory
)
try {
$body = @{ "@odata.id" = "https://graph.microsoft.com/beta/deviceManagement/deviceCategories/$DeviceCategory" }
Invoke-MSGraphRequest -HttpMethod PUT -Url "deviceManagement/managedDevices/$DeviceID/deviceCategory/`$ref" -Content $body
}
catch {
Write-Error "Failed to set device category: $_"
}
}
$DeviceID = 'ADD-DEVICE-ID'
$DeviceCategory = 'ADD-THE-DEVICE-CATEGORY-ID'
Set-DeviceCategory -DeviceID $DeviceID -DeviceCategory $DeviceCategory