Finding Empty Device Collections in SCCM

, , , , , , , ,

     Today’s script is going to be almost a one-liner, but a very useful one.  I had found SQL queries that would do this same thing, but I frequently find myself working on a computer that does not have the SQL management software installed on it, and this query doesn’t run cleanly through the SCCM Management software.  However, I’m always on a computer with PowerShell and since this runs through WMI, you don’t even need to connect to the SCCM site code drive.
     Having the right amount of device collections in SCCM is a bit of a balancing act. You don’t want so few collections that you don’t have a good way to sort out your clients logically, but you don’t want so many that you’ve gunked up your database with entries you’re never actually going to use. On top of that, some of the companies I’ve contracted with have had many collections that never held a single client. This script will go through and find those empty collections for you.   If you just want the PS1 file, click HERE.

Step 1: Initializing a few variables
Typically, if I’m working with SCCM through WMI, I like to setup a few variables in my shell right away to make my life easier and save some keystrokes throughout the day.
$siteServer = “PriServer1″ # whatever the name of your primary server is
$namespace = “root/SMS/site_TST” # root/SMS/site_  whatever your site code is

If you’re constantly making WMI calls to SCCM, being able to just enter those variables instead of typing it all out can make things easier. At least, that’s what I’ve found. 

Step 2: Get your SCCM Device Collections
This script is going to be done on a single line, but I’ll break it out into chunks first. The first thing we need to do is pull all of the device collections from SCCM.
Get-WmiObject -Namespace $namespace -ComputerName $siteServer -Class SMS_Collection -filter ‘CollectionType =2’
 
If you wanted to pull user collections, you would change ‘CollectionType = 2’ to ‘CollectionType = 1’
If you want to get both sets of collections, just leave out the -filter portion entirely.

Step 3: Check Those Collections for Members
There are a couple ways you could do this. You could pipe your collections to a ForEach loop with an if statement in it. Alternatively, I choose to just pipe the first cmdlet into a where statement that does it for me.
| where {$colID = $_.CollectionID;(Get-WmiObject -Namespace $namespace -ComputerName $siteServer -class SMS_FullCollectionMembership -filter “CollectionID=’$colID'”).count -eq 0}

What this is doing is setting a variable called “$colID” to be the collection ID number from the collection passed through the pipe.  Then, we’re going to do a WMI query to the SMS_FullCollectionMembership class, which is a class that maintains a list of every device/user to collection association. We’re adding a filter to only show collection IDs that match the one we want, counting up all the members, and if that number equals 0, we know the collection has nothing in it.

Step 4: Profit
If you just stop there, you have a set of list-formatted data that, while not pretty, does contain all the information and objects you need to do work. It’s not the easiest thing to read, but it does give you a very solid information dump about the empty collection that looks something like this:

Chances are, if you’re generating this report for a manager, customer, etc, they’re going to want it formatted a bit nicer, and they’ll probably want it in an Excel spreadsheet.  The easiest way to do this is:
| select Name,CollectionID | export-csv C:usersMyUserDocumentsEmptyCollections.csv -noTypeInformation

 Alternatively, if you get the go-ahead to remove these device collections, instead of piping to a select/export-csv statement, you can pipe to remove-wmiobject instead. 
For the love of god, run it with -whatif first.  

Thanks for reading, and if you have any questions, feel free to post them in the comments. 

SSRS – Client Health Dashboard

, , , , ,
Client Health Dashboard
In previous posts I was speaking about soon to be releasing a series of SSRS reports based on troubleshooting. The first in the series I am trying to have is a focus on Client Health Overview. This dashboard will later be include drill down functionality to multiple other reports as soon as I can finish making and validating them. This dashboard is something that I put together for my current customer to get a brief overview of client health. There will be a few more items added to the home page at a later time which will be focused on count vulnerable/unpatched systems
Currently we can see in this report Active clients, MP information, Client version counts, OS version counts. There are even a few top level items you should keep an eye on like duplicate systems, mac addresses, systems running out of space, or why clients failed to install/re-evaluate. These will all be further expaneded on when the full client health troubleshooting series wraps up over the next few weeks.
SSRS Client Health Dashboard

Link to the Report: https://gallery.technet.microsoft.com/SSRS-Client-Health-6bfb794f

Some code used from: Greg Ramsey and Eswor Koneti

Future Dashboards w/ drilldowns coming soon.

– Client Health (will be finished soon)

  • This will also include drill downs into several other reports

– Software Deployment (For Packages / For Apps)

  • This will also include how to troubleshoot just like this other report
    SSRS Client Health Dashboard
– Infrastructure health (Primary/DP/SQL/DP etc health focused)
  • This will also include how to troubleshoot just like this other report
  • This will also include drill downs into several other reports
– Windows Migration Summary
SSRS Client Health Dashboard

 

– Collection evaluation

 

SCCM Power Plan SQL Queries

, , , ,

SCCM Power Plan SQL Queries

In one of my customers environments there was a request for a quick review of ConfigMgr SCCM Power Plan settings. This turned out to show us that there were over 20+ power plans in the environment and needed to be reduced. Below is the quick query I came up with for the customer.

— individual systems with power plans and collection they belong to
select
SMS_R_System.Name0 AS [System Name],
V_Collection.Name AS [Collection Name],
__R_MANAGEMENT_CONFIGURATION0.NonPeakPowerPlanName00 AS ‘Non Peak Power Plan Name’,
__R_MANAGEMENT_CONFIGURATION0.PeakPowerPlanName00,
__R_MANAGEMENT_CONFIGURATION0.PowerConfigID00 AS [Collection Power setting Source] from
vSMS_R_System AS SMS_R_System
INNER JOIN POWER_MANAGEMENT_CONFIGURATION_DATA AS __R_MANAGEMENT_CONFIGURATION0 ON __R_MANAGEMENT_CONFIGURATION0.MachineID = SMS_R_System.ItemKey
Inner JOIN V_Collection on V_Collection.CollectionID = __R_MANAGEMENT_CONFIGURATION0.PowerConfigID00
Order by
SMS_R_System.Name0

 

SCCM Power Plan

— collections with count of systems with power plans
select
V_Collection.Name AS [Collection Name],
__R_MANAGEMENT_CONFIGURATION0.PowerConfigID00 AS [Collection Power setting Source],
count (V_Collection.Name) AS Count,
__R_MANAGEMENT_CONFIGURATION0.NonPeakPowerPlanName00 AS ‘Non Peak Power Plan Name’,
__R_MANAGEMENT_CONFIGURATION0.PeakPowerPlanName00
from
vSMS_R_System AS SMS_R_System
INNER JOIN POWER_MANAGEMENT_CONFIGURATION_DATA AS __R_MANAGEMENT_CONFIGURATION0 ON __R_MANAGEMENT_CONFIGURATION0.MachineID = SMS_R_System.ItemKey
Inner JOIN V_Collection on V_Collection.CollectionID = __R_MANAGEMENT_CONFIGURATION0.PowerConfigID00
Group by
v_Collection.Name,
__R_MANAGEMENT_CONFIGURATION0.NonPeakPowerPlanName00,
__R_MANAGEMENT_CONFIGURATION0.PeakPowerPlanName00,
__R_MANAGEMENT_CONFIGURATION0.PowerConfigID00

 

SCCM Power Plan

In a future blog post I’ll drop a massive amount of sql queries you should find helpful in any environment.