Wednesday, November 28, 2007

SMS tool: What collection is a computer or User in?

[NOTE: I have updated this with a new version to work with SCCM and Maintenance windows collections-with-maintenance-windows (May 2008)]
OK I have this pulled from my C# app to vbscript. It isn't pretty but it works. The one problem is that I didn't create an array to sort the list so if you wanted sorted you will need to do it. I will update this later with the sort feature. Obviously I make no warranty. You will need to add the sever data and change the path to match your computer. Copy the vbscript to your folder, run the reg file and you will then see it in the MMC when you right click on a computer.

This will work with SMS 2003. To work with SCCM you will need to change the GUID and possible look at the WMI query for changes
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\NodeTypes\{4D26C0D4-A8A8-11D1-9BD9-00C04FBBD480}\Extensions\SMS_tools\xCol Mem]
"Name"="Collection Membership"
"Description"="Show what collections a computer is in"
"CommandLine"="wscript.exe \"c:\\Program Files\\MCNS\\Collections\\computercols.vbs\" ##SUB:ResourceID##"

'------------ SCCM console -----------------
c:\program files Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions\Actions\7ba8bf44-2344-4035-bdb4-16630291dcf6


<actiondescription class="Group" displayname="MCNS" mnemonicdisplayname="MCNS" description="MCN Tools" sqmdatapoint="100">
<actiondescription class="Executable" displayname="Collection Listing" mnemonicdisplayname="Collection Listing" description="Display machine Collection membership">
<filepath>C:\Program Files\MCNS\collections\computercols07.vbs


---------------------------computercols.vbs -----------------------------------------------
Dim CollectionArray(100)

Set objArgs = WScript.Arguments
if (objArgs.count > 0) then
MyPos = InStr(objArgs(0), ":")
ResourceID = wscript.arguments.item(0)
end if

Set Shell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator")
set SWbemServices = SWbemLocator.ConnectServer("server","root\SMS\site_XXX")
strQuery = "select * from SMS_CollectionMember_a where ResourceID='"+ ResourceID +"'"
Set Collections = SWbemServices.ExecQuery(strQuery)
for each Collection in Collections
set Collectionfound=SWbemServices.Get("SMS_Collection='" & Collection.CollectionID & "'" )
'Sort Collection list
for i = count - 2 To 0 Step -1
for j= 0 to i
if CollectionArray(j)>CollectionArray(j+1) then
end if

''' print out the collection listing
For NC = 0 to count-1
WhatCollections= WhatCollections & CollectionArray(NC) & VbCrLf
Wscript.echo WhatCollections