After doing some research on the net I discovered there is very little information out there on this topic. After a little bit of tinkering I wrote this code to run audit inventories on our database. I streamlined the SQL query to the best of my SQL ability if anyone else has some faster code feel free to let me know. SCCM SQL tables are interesting in that they query very much like any SQL database. This makes them very accessible via scripts if you know the table structure. The difficult issue I ran into was when I went to combine the tables. The data was no longer accessible. I knew better. The script was crashing. It wasn’t the query I was using because it worked perfectly as a SCCM Collection. Any other way this would be a very long process. But if you feed this query one serial at a time you will get some very nice results that you can use Vlookup on in Excel.
Naturally this will fail on any system that is missing it’s hardware inventory.
When combining tables you need to request the data in the same way you put it in.
SQL Example Code:
"select SMS_R_System.ResourceId, SMS_R_System.Name, SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceID = SMS_R_System.ResourceId WHERE SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber = '1XS2AC'"
To retrieve the Serial Number Column it would be something like this:
Serial = WhateverSQLObject.SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber