Blog
By Pete Zerger on 8/17/2009 6:32:37 AM • Rank (2118) • Views 2191
0

0

I was just working on writing a few Powershell scripts to make a few administrative tasks more convenient for a client. While enumerating members of a ConfigMgr collection is not one of them, this is the first step in scripting several tasks of interest. Here’s a sample script that does just that. In coming weeks, I’ll try to share several examples from my one of my current projects.

Syntax

This one has three required parameters.

  • SiteCode – the 3 letter ConfigMgr site code
  • SCCMServer – Name of the site server
  • CollName – Displayname of the collection for which you’d like to enumerate membership.

Example:

enumcoll.ps1 –SiteCode CON  -SCCMServer ‘server1’ –CollName ‘All Systems’

Sample Code

Just cut-and-paste and save with name of your choice and a .ps1 extension.

   1: Param($SiteCode,$SCCMServer,$CollName) 
   2:  
   3: # Get a list of collections and find the object to build the collection list.
   4: $Collection = Get-WmiObject -ComputerName $SCCMServer  -Namespace `
   5: "root\sms\site_$SiteCode" -Class 'SMS_Collection' 
   6:  
   7: $MyCollection = $Collection | Where-Object { $_.Name -eq $CollName } 
   8:  
   9: # Grab the Resource ID of the collection
  10: $MyCollectionMembers = Get-WmiObject  -ComputerName $SCCMServer -Namespace `
  11: "root\sms\site_$SiteCode"  -Query "select * from SMS_CM_RES_COLL_$($MyCollection.CollectionID)" 
  12:  
  13: #Echo member of the collections to screen
  14: Foreach ($member in $MyCollectionMembers) {
  15:  $oldErrCount = $error.Count
  16: $Name = $member.Name.ToString()
  17: Write-Host $Name 
  18: }

Thanks to MVP Marcus Oh for some samples that helped get the ball rolling!

Comments - Comment RSS


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/rdsd2g

Top Contributors
Featured Members
Pete Zerger
Points: 72533
Level: System Center Expert
Tommy Gunn
Points: 47345
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Andreas Zuckerhut
Points: 30700
Level: System Center Expert
Stefan Koell
Points: 30179
Level: System Center Expert