After installing SP2 you will need to create collections for Windows 7, Server 2008 R2 and possibly Windows Vista and Server 2008 if you have not already done so, I used the following script to create 4 new collections:

Click View Source to viewcopy script

The script does not check for existing collections and I have only used it in a test environment so use at your own risk.

bitdoctor
· March 17, 2011 at 1:11 pm

I have to agree with ChrisC – I copied the code exactly and I ran it on my SCCM server; and I also get the “type mismatch.
Mine says “Line 23, Character 2, Type Mismatch, Code: 80041005, Source: SWbemObjectEx”

So, there is definitely/clearly something wrong with your posted code. It would be kind of you to take the code and run it (modify the collection on your test server to “TestColl” and comment out the Vista, Win7 & Win Server collections; and you will see the error. (YES, I KNOW: THE THREAD/RESPONSES ARE OVER A YEAR OLD 🙂

Eventually, I will figure it out, and I also am referencing some of the links you mentioned; as well as other expert links regarding programmatically creating collections. It’s just extremely frustrating to have wonderful code like this that does not work, due to possibly one single line and/or some object/connection not being properly made/created.

The error is, as ChrisC mentioned, right around the swbemconnetion.Get command:

‘ Create the collection.
Seems to be the “Set Token” line – I tried changing Sms_St to SMS_ST, as that is the ‘official’ beginning designation of that class, but the problem seems to be a bit deeper than that.

So, the error seems to point back to the “Set swbemconnection command at the very beginning:

Set swbemLocator=CreateObject(“WbemScripting.SWbemLocator”)
Set swbemconnection=swbemLocator.ConnectServer(“.”, “rootsms”)
Set providerLoc=swbemconnection.InstancesOf(“SMS_ProviderLocation”)

Any hints or clues would be greatly appreciated; either way, I am still researching.

bitdoctor
· March 17, 2011 at 1:36 pm

Ok, maybe not exactly. You did use “InstancesOf” – so, I am not exactly sure, but that may allow the ‘For Next’ loop to proceed properly.

BUT, I did find a spelling/syntax error: You had “location” vs. “Location” – and those are two completely separate strings, as far as I know; here is the place where one discrepancy resides:

For Each Location In providerLoc
If location.ProviderForLocalSite = True Then
Set swbemconnection = swbemLocator.ConnectServer(Location.Machine, “rootsmssite_” + Location.SiteCode)
Exit For
End If
Next

So, you have the “For Each Location” (upper-case “L”), but then you have “If location” (lower-case “l”).

Okay, I am still researching and still unable to get this to run. Either way, Thanks again for posting it!

For Each Location In providerLoc
If location.ProviderForLocalSite = True Then
WScript.Echo Location.Machine
WScript.Echo Location.SiteCode
WScript.Echo "Connecting..."
Set swbemconnection = swbemLocator.ConnectServer(Location.Machine, "rootsmssite_" & Location.SiteCode)
If Err.Number0 Then
Wscript.Echo "Couldn't connect: " & Err.Description
WScript.Quit
End If
Exit For
End If
Next

' Save the new collection and save the collection path for later.
Set collectionPath = newCollection.Put_

' IMPORTANT: If you do not specify the relationship, the new collection will not be visible in the console.
Set newSubCollectToSubCollect = connection.Get("SMS_CollectToSubCollect").SpawnInstance_
newSubCollectToSubCollect.parentCollectionID = "COLLROOT" ' Define to what collection the new collection is subordinate.
newSubCollectToSubCollect.subCollectionID = CStr(collectionPath.Keys("CollectionID"))
newSubCollectToSubCollect.Put_ ' Save the subcollection information.

' Create a new collection rule object for validation.
Set queryRule = connection.Get("SMS_CollectionRuleQuery")
validQuery = queryRule.ValidateQuery(queryForRule) ' Validate the query (good practice before adding it to the collection).

Meta

Related Posts

You see error -2146232060 when attempting to configure your ACT database using the following steps: In the Configuration Manager console, navigate to System Center Configuration Manager / Site Database / Computer Management / Application Compatibility Read more…

Logon on to a virtual Machine and insert integration service setup disk. If you do not have a virtual machine up and running you can mount %windir%system32vmguest.iso Extract the drivers by performing an admin install Read more…