Skip to content

Instantly share code, notes, and snippets.

@MarkusBux
Last active October 10, 2024 00:00
Show Gist options
  • Save MarkusBux/ad8ab3d5baeb9ac521b5165e67bf2d65 to your computer and use it in GitHub Desktop.
Save MarkusBux/ad8ab3d5baeb9ac521b5165e67bf2d65 to your computer and use it in GitHub Desktop.
Samples for ConfigMgr Custom Device Properties available since ConfigMgr2107
# Samples to work with custom properties for devices
# https://docs.microsoft.com/en-us/mem/configmgr/develop/adminservice/custom-properties
# Specify Siteserver and Device
$provider = "<ConfigMgrFqdn>"
$resourceID = <ResourceIdOfDevice>
# Get all Custom Device Properties
$uri = "https://$provider/AdminService/v1.0/Device/AdminService.GetExtensionData"
Invoke-RestMethod -Method "Get" -Uri $uri -UseDefaultCredentials
# Get Properties for a single device
$uri = "https://$provider/AdminService/v1.0/Device($resourceID)/AdminService.GetExtensionData"
Invoke-RestMethod -Method "Get" -Uri $uri -UseDefaultCredentials
# Set a List of properties (create or update)
$uri = "https://$provider/AdminService/v1.0/Device($resourceID)/AdminService.SetExtensionData"
$body = "{ExtensionData:{""AssetTag"":""0580255"",""Location"":""MyLABLocation"",""Test"":""MyTestValue""}}"
Invoke-WebRequest -Method "Post" -Uri $uri -UseDefaultCredentials -Body $body -ContentType "application/json"
# Update properties (update) without deleteing other properties
$uri = "https://$provider/AdminService/v1.0/Device($resourceID)/AdminService.SetExtensionData"
$body = "{ExtensionData:{""AssetTag"":""0815"",""Location"":""MyNewLocation""}}"
Invoke-WebRequest -Method "Post" -Uri $uri -UseDefaultCredentials -Body $body -ContentType "application/json"
# Delete one or more dedicated properties
$uri = "https://$provider/AdminService/v1.0/Device($resourceID)/AdminService.DeleteCustomProperties"
$body = "{PropertyNames:['Test','Location']}"
Invoke-WebRequest -Method "Post" -Uri $uri -UseDefaultCredentials -Body $body -ContentType "application/json"
# Delete all properties for a single device
$uri = "https://$provider/AdminService/v1.0/Device($resourceID)/AdminService.DeleteExtensionData"
Invoke-WebRequest -Method "Post" -Uri $uri -UseDefaultCredentials
# delete all properties for all devices
$uri = "https://$provider/AdminService/v1.0/Device/AdminService.DeleteExtensionData"
Invoke-WebRequest -Method "Post" -Uri $uri -UseDefaultCredentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment