Powershell–Getting information from AD into the SCCM database

Recently I was asked to deliver a report on the count of machines in AD and their location. In our environment we use a computer name identifier to designate location. But, you could use OU information or eve AD Site information. So, I wrote a PowerShell script that grabs all three and puts the information into SQL. You can then merge the tables together and create a view. You may be asking, “doesn’t SCCM System Discovery provide this information?” Well, yes and no. My PowerShell script returns more computers than SCCM is discovering. Plus, the PowerShell script also returns information from AD Sites and Services as well as OU Description that can’t be obtained using SCCM discovery.