| Is there a
tool or a way to import machines in a collection ? I used the Make
collection tool, but it only allows 1 machine after another. I'd like to
find something to import from an Excel file.
Contributed By: Paul Thomsen [MS]
You could
script it. Here's a script that adds users to a collection. Adding
machines, and reading from Excel would be relatively minor modifications.
if
wscript.arguments.count<>1 then
wscript.echo "One argument please - the collection"
wscript.quit
else
newname=wscript.arguments(0)
end if
Dim lLocator
Set lLocator = CreateObject("WbemScripting.SWbemLocator")
Dim gService
Set gService = lLocator.ConnectServer(, "root\sms\site_WMA")
'figure out the current user, as a resource ID
Dim username
Dim oWshNetwork
Set oWshNetwork=CreateObject("Wscript.Network")
username = oWshNetwork.UserName
Dim ResID
Dim User, Users
Set Users = gService.ExecQuery("Select * From SMS_R_User WHERE Name
LIKE ""%" + username + "%""")
For Each User In Users
If UCase(User.username) = UCase(username) Then ResID =
User.ResourceID
Next
'you may want to handle the contingency of a user that is new to the
domain and
'hasn't been added (yet) to the list of SMS users
'now to do the real work...
'start by spawning a blank instance of a collection rule
Dim CollectionRule
Set CollectionRule =
gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
'and give that instance the values it needs - this is an important
point, of course
CollectionRule.ResourceClassName = "SMS_R_User"
CollectionRule.RuleName = "ResourceID=" & ResID
CollectionRule.ResourceID = ResID
Dim oCollectionSet
Dim oCollection
Set oCollectionSet = gService.ExecQuery("Select * From
SMS_Collection")
'walk through the enumeration that was returned from the collection
query above and
'select the one provided as a parameter
For Each oCollection In oCollectionSet
If oCollection.Name = newname Then
oCollection.AddMembershipRule CollectionRule
If Err.Number = 0 Then
Wscript.Echo "You were added to the " + oCollection.Name
+ " collection!"
End If
End If
Next
|