ConfigMgrConfigMgr

SCCM Powershell Tools

I’ll get this out of the way right now: I think SCCM’s PowerShell module is garbage.  It’s slow, it doesn’t work like you’d expect a lot of the time, and it’s got absolutely nothing on the ease of use and functionality of something like the ActiveDirectory module.  Thankfully, WMI is still a thing, and that gives us an excellent way to interact with SCCM via PowerShell. With that in mind, here’s some quick and dirty (but still useful) PowerShell functions I’ve put together. Most, if not all, PowerShell tools I’ve written for SCCM can also be done with SQL queries and commands, so if that’s more your thing, have at.

Find-ClientByMac
File can be downloaded from my technet gallery here
This is a simple enough tool. It will find any clients in the SCCM database that match a “like” query against the MAC address you provide.  This is handy for finding duplicate objects with the same MAC, which can royally screw with trying to PXE boot and image a computer.

Function Find-ClientByMAC ($inputMac){
$namespace = “root/SMS/Site_TST”
$siteServer = “testServer”

    $inputMac = $inputMac.Replace(” “,””)
$inputMac = $inputMac.replace(“-“,”:”)

if ($inputMac -notlike “*:*”)
{
$count = 0
while ($count -lt ($inputMac.Length – 2))
{
$inputMac = $inputMac.Insert(($count)+2,’:’)
$count += 3
}
$inputMac
}
Get-WmiObject -Namespace $namespace -ComputerName $siteServer -class SMS_R_System -filter “MACAddresses like ‘%$inputMac%'”
}


Something to keep in mind with SCCM is that it stores MAC addresses with “:” between each pair, but your computer’s IPConfig command will give it to you with “-“‘s.  This will replace a – with a :, and if you just feed it a straight set of text, it will insert the “:” between each pair.
This will find any computer that matches the MAC you provided and returns with a WMI object of the SMS_Device class.  If you want to delete the duplicate objects, you can simply pipe to the remove-wmiobject command to delete.

 

ALSO CHECK : N-2 WIM and Task Sequence Managment

Peter Vanhaverbeke

I started my journey into automation out of laziness. It started with our desktop support lead telling us we needed to manually install Office 2013 on 250 computers and me downloading a copy of PsTools. I moved on from batch to PowerShell several years ago and haven't looked back. Don't even come at me with some VBscript you found online because VBScript was given to mankind by the devil.
Most days, you can find me writing scripts for people in exchange for bottles of reasonably priced Gin or drinking a growler of something local while playing Kerbal Space Program.

Add comment

thirteen + 20 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

%d bloggers like this: