Re: Scripting Collections



Soren,

I picked up a piece of software called MAKECOLL from the myitforum web site;
very easy to use and troubleshoot if (like me) scripting is not one of your
strengths.
Can create both Query based and Direct Membership collections and you can
run it from a workstation.

Bernie

"Kim Oppalfens <MVP>" wrote:

What error are you getting?

--
"Everyone is an expert at something"
Kim Oppalfens - Sms Expert for lack of any other expertise
Windows Server System SMS - MVP


"Sonnichsen" <Sonnichsen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:264F457C-9752-4456-BACB-3ABEAA86CA60@xxxxxxxxxxxxxxxx
Hi

I'm trying to automate the creation of collections by the use of the
following script, however I keep getting an Generic Error Message. The
Collection is being created, but the Collection Query is never created.
Thanks in advance.

Soren

if wscript.arguments.count<>1 then
WScript.Echo "One argument please - the collection name"
WScript.Quit
else
newname = wscript.arguments(0)
end if
Set lLocator = CreateObject("WbemScripting.SWbemLocator")
Set gService = lLocator.ConnectServer( , "root\sms\site_100")
alreadyused = False
Set Collections = gService.ExecQuery("Select * From SMS_Collection")
For Each Collection In Collections
If Collection.Name = newname Then alreadyused = True
Next
If alreadyused Then
MsgBox "This collection name is already in use. Please enter a different
name."
Else
Dim newCollection
Set newCollection = gService.Get("SMS_Collection").SpawnInstance_()
newCollection.Name = SHSTest
newCollection.OwnedByThisSite = True
newCollection.comment = "this is just a " & newname & "-test"
path=newCollection.Put_
path=newCollection.Put_
Set Collection=gService.Get(path)
newcollectionid= Collection.CollectionID
Dim newCollectionRelation
Set newCollectionRelation = gService.Get( "SMS_CollectToSubCollect"
).SpawnInstance_()
newCollectionRelation.parentCollectionID = "COLLROOT"
newCollectionRelation.subCollectionID = newcollectionid
newCollectionRelation.Put_
Set CollectionRule =
gService.Get("SMS_CollectionRuleQuery").SpawnInstance_()
CollectionRule.RuleName = newname
CollectionRule.QueryExpression = "select * where SystemOUName is like "
&
newname & "" 'add the rule to the collection
Collection.AddMembershipRule CollectionRule
If Err.Number = 0 Then
WScript.Echo "The query was added to the " + Collection.Name + "
collection"
Collection.RequestRefresh
End If
End If 'this is the end of the test for a unique collection
--
Soren Holst Sonnichsen


.


Loading