Skip to main content

PowerShell + SCCM : Get Resource Collection Membership

Recently at our PowerShell Bangalore User group, we had fun participating in a one day PowerShell + ConfigMgr Hackathon event. Where we had a bunch of ConfigMgr admins worked on using Azure to deploy a full fledged ConfigMgr Lab, also we had fun interacting with each other.

Below pic was the theme for the event, says it all ;)




My friend Harjit  suggested few ideas for the Hackathon. Below is one of the ideas:

"Script that can tell me which collections a particular system or several Systems belong to"


The Final Script is available @Technet for Download 

  

Credits - There is a post by MVP David O'Brien (link in Resource section) which served as a base for my function. The final Function does the following :
  • Fetches the Collection the Resource (Device/User) is member of.
  • Uses WQL Queries to enhance the performance.
  • For the User resource type, it does a WildCard search  .
Also I took my first shot at writing the Pester tests for the Function. Getting the hang of writing unit tests now.


Usage : 

After dot sourcing the Script, you can invoke the Function to either get the information about a Device or User. 
Get-ResourceCollectionMemberhip -Name dexterposh -ComputerName dexsccm -ResourceType User 

    Name                                          ResourceType                                  CollectionName                               CollectionID                                
    ----                                          ------------                                  --------------                               ------------                                
    dexterposh                                    User                                          TestUserCollection                           DEX00032                                    
    dexterposh                                    User                                          All Users                                    SMS00002                                    
    dexterposh                                    User                                          All Users and User Groups                    SMS00004  


If you want the Collection Membership (Name & CollectionID ) of the User Resource then invoke the function like below:



Get-ResourceCollectionMemberhip -Name dexchef -ComputerName dexsccm  

    Name                                          ResourceType                                  CollectionName                               CollectionID                                
    ----                                          ------------                                  --------------                               ------------                                
    dexchef                                       Device                                        Server2012                                   DEX00038                                    
    dexchef                                       Device                                        Server2008                                   DEX00039                                    
    dexchef                                       Device                                        All Systems                                  SMS00001                                    
    dexchef                                       Device                                        All Desktop and Server Clients               SMSDM003 


Below is the GIF showing the above in action :





Resources :


How to find ConfigMgr Collection Membership of client using PowerShell

http://www.david-obrien.net/2014/01/find-configmgr-collection-membership-client-via-powershell/

How to enumerate members of a collection
https://msdn.microsoft.com/en-us/library/hh949334.aspx

Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

PowerShell : Trust network share to load modules & ps1

Problem Do you have a central network share, where you store all the scripts or PowerShell modules ? What happens if you try to run the script from a network share ? or if you have scripts (local) which invoke scripts or import PowerShell modules stored on this network share ? Well you would see a security warning like below (Note - I have set execution policy as 'Unrestricted' not 'bypass' here): Run a .ps1 from the network share Well this is a similar warning, which you get when you download scripts from Internet. As the message says run Unblock-File cmdlet to unblock the script and then run it, let's try it.