SCCM – PowerShell – Return Device Name using ResourceID

email me

Template Example

# MrNetTek
# eddiejackson.net/blog
# 6/3/2020
# free for public use
# free to claim as your own

$Server = "YOUR_SITE_SERVER_NAME"
$Namespace ="root\sms\site_SITE_CODE"
$ResourceID = "SOME_RESOURCE_ID"

Get-WmiObject -Query "Select ResourceID,ResourceNames from SMS_R_System where ResourceID='$ResourceID'" -Namespace $Namespace -ComputerName $Server | ForEach-Object {$Computer = $_.ResourceNames[0]}

Write-Host $Computer

 

Production Example

$Server = "sccmsiteserver"
$Namespace ="root\sms\site_001"
$ResourceID = "61545625"

Get-WmiObject -Query "Select ResourceID,ResourceNames from SMS_R_System where ResourceID='$ResourceID'" -Namespace $Namespace -ComputerName $Server | ForEach-Object {$Computer = $_.ResourceNames[0]}

Write-Host $Computer