ConfigMgr & PoSh Quick Tip: Get-CMResource

Ever need to quickly get the mac address for a device in Configuration Manager and don’t want to wade through the console to find it?  My logic said that the Get-CMDevice cmdlet would do the trick.  However, MAC isn’t one of the attributes returned.

A couple of releases ago, the ConfigMgr team introduced a new cmdlet – ‘Get-CMResource’.  Using this, we can snag the MAC Address quickly

Get-CMResource -Name MyDeviceName -Fast | Select Name,MacAddresses

One of the primary uses of this cmdlet, in my experience, is finding rogue ‘Unknown’ devices. During operating system deployment, a device will appear in the database with the name ‘Unknown’ until the task sequence gets to a point of naming the device.  From time to time, I have found that OSD will fail for one reason or another and the ‘Unknown’ device will need to be removed. Rather than sorting through any devices with the name ‘Unknown’, I can simply run a quick one-liner to find the correct device.

Get-CMDevice -Name Unknown | ForEach-Object {Get-CMResource -ResourceId $_.resourceid -Fast | select name,macaddresses,resourceid}

Once I know the ResourceID of the device in question, I can use the one-liner below to remove it.

Remove-CMResource -ResourceID MyresourceIDHere

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s