Thursday, April 10, 2014

PowerShell + SCCM 2012 R2: Get the Client Info Easy Way

One of my friend Krishna called and asked me on how to get the report for the  Management Point to which SCCM clients (part of a Collection) report to.

This is normal day to day task in a ConfigMgr Admin's life and most of us would go and use Reports in Configuration Manager . But he wanted to do this using PowerShell...... hmmm :-?  Now you are talking :-b

If you are using Configuration Manager 2012 and haven't started using PowerShell then you as missing one of the Coolest things that can make your job easy.

In ConfigMgr 2007 we had an option to export the list of members from a Collection , see below:

This was convenient but sadly it's not there now.

But we can do a lot more if we choose to use PowerShell here.

This is not a very complex thing to do if you are comfortable with PowerShell, so I am going to do it 2 ways:

  1. Easy Way : using cmdlet Get-CMDevice
  2. WMI Way :P (next Post)

 Easy Way : using cmdlet Get-CMDevice

On your ConfigMgr Console top left corner Click and select "Connect via Windows PowerShell" (this is the last time am gonna put this in my post :) )

After you have your Console opened the ConfigurationManager PowerShell module will be loaded and you can now use the cmdlet Get-CMDevice. Note - When the console opens you will be placed in the drive named after your SiteCode something like DEX:\ in my case. If we want to run cmdlets shipped with ConfigMgr then that we need to do from inside this PSProvider.

Go ahead and open the help for the cmdlet and see that there are a lot of parameters and parameter sets but looking for the marked one here:

Well you can use this cmdlet in a lot many ways but as per my requirement I want to get the Devices in a specific collection and generate report. 

Let me take the "All Systems" as the collection here as I don't have many machines in my LAB. Below is a shot of my current members of it:

Now you can see I have already gone ahead and added the Management Point and Operating System property to the Column view (just have to right click on it and select these).

So below cmdlet will give you information about all the devices, the properties are overwhelming in number so going to save it in a variable here:

$Members = Get-CMDevice -CollectionName "All Systems"

To know what all properties the members of the Collection have, we can use :

$Members | Get-Member -MemberType Property

If you scroll down enough you will see there is a property named lastmpservername and deviceos , so go ahead and do this

$Members | select name,lastmpservername,deviceos

But strangely enough nothing gets returned back, Why ? What am I doing wrong here ?  :-/

Well I had mentioned in my first post that the Property references in here are case-sensitive and I don't know why it is the way it is. #-o

Work Around is put the property names exactly as they appear when we did this $Members | Get-Member  (Note below the proper case of the Property Names)

This issue has been fixed in the new R2 CU1  :-$

Now back to what we are doing. With PowerShell there are lot of things which you can do like sort on basis of LastMPServerName property and then group the devices having same LastMPServerName property :

Endless possibilities -- You can create a CSV of this report, an HTML report etc.

The only problem with this cmdlet is it doesn't allow me to specify a subset of the properties I want back, it just gives me back the whole set. So if there are lot of members in a collection it might take a while to run the cmdlet. Here is where the WMI way will be a bit efficient.

Using WMI/CIM we can specify the properties we want back using the WQL Query hence more efficient. I will be showing this in the next post as I have observed my posts length is increasing day by day...need to break it in pieces.

Till then /bye


  1. Hi,

    This is one best way to get the details for Device Collections,
    by the way user collection details also we will aproach the same way as well ?


    1. Hi Krishna,
      I posted the another way using CIM here :
      To get the User info you can use the Get-CMUser cmdlet too :)

  2. Case Sensitive for Prperties also .....!

  3. Hi DexterPOSH,

    How can I set up a test lab on a computer at home? I have access to Windows Server 2012 and 2008 for a year through a student account, and I can get trial version of SCCM for 180 days, AND I am doing PowerShell scripting at my internship for this summer.

    Your blog post is very helpful and I am using it more and more as I become better at PowerShell.

    Thank you!

    -PowerShell Intern

    1. Hey there,

      Head out to and check out the step by step guide for setting up LAB.
      You can use a Virtualization solution like Hyper-V, VirtualBox, VMware workstation etc to setup a server core Domain Controller and then add a ConfigMgr Primary Site.

      Glad that you are exploring the ins and outs using PowerShell. It will help you a lot in understanding the ConfigMgr product better.