Sie sind auf Seite 1von 3

'==========================================================================

'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009
'
' NAME: Add list of clients to existing collection (colladd.vbs)
'
' AUTHOR: Mark Nunn (2006) (website now offline)
' Updated 2009
' DATE : 5/9/2009
'
' COMMENT: This scripts adds a list of machine names from a file to a SCCM colle
ction.
' It can also list all collections on a server.
'
' UPDATES: Cleaned up commenting in script.
' Added Syntax info when incorrect arguments are specified.
' Tested and as expected, works on SCCM 2007 R2
'==========================================================================
Set fso = CreateObject("Scripting.FileSystemObject")

Set arrArgs = WScript.Arguments


if (arrArgs.Count = 0) Then
wscript.echo ("Colladd.vbs v1.0")
wscript.echo ("")
wscript.echo ("EXAMPLE")
wscript.echo ("Colladd.vbs server filename collectionID - to add from fi
le to collection")
wscript.echo ("")
wscript.echo ("EXAMPLE")
wscript.echo ("Colladd.vbs server - to list collectionID's")
else
on error resume next
'Error handling
'Set variables from command line
strServer=arrArgs(0)
if (arrArgs.Count = 3) Then
strFile=arrArgs(1)
strCollID=arrArgs(2)
end if
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSMS = objLocator.ConnectServer(strServer, "Root/SMS")
'Connect to sms
objSMS.Security_.ImpersonationLevel = 3
wscript.Echo("Connecting to Root/SMS on " & strServer)
set colSiteDetails=objSMS.ExecQuery("select Machine, SiteCode from SMS_P
roviderLocation where ProviderForLocalSite=True")
For Each insSiteDetails In colSiteDetails
strSiteCode=insSiteDetails.SiteCode
next
wscript.Echo("Connecting to Root/SMS/site_" & strSiteCode &" on " & strS
erver)
set objSMS=objLocator.ConnectServer(strServer, "root/SMS/site_" + strSit
eCode)
wscript.Echo("Connected")
'if not all arguments supplied list colelctions
if (arrArgs.Count < 3) Then
set colCollections=objSMS.ExecQuery("select CollectionID, Name f
rom SMS_Collection ORDER BY CollectionID")
wscript.echo("CollectionID" & vbTab & "Name")
For Each insCollection In colCollections
wscript.echo(insCollection.CollectionID & VbTab & insCol
lection.Name)
Next
'otherwise add from file
else
set instColl = objSMS.Get("SMS_Collection.CollectionID="&"""" &
strCollID & """")
'check valid collection
if Instcoll.Name="" then
wscript.echo (strCollId &" Not Found")
Else
'open file of machines
Set filNames = fso.OpenTextFile(strFile)
if (filNames) Then
While not filNames.AtEndOfStream
'read each line and find resource ID
strMachine=filNames.ReadLine
set colNewResources=objSMS.ExecQuery("SE
LECT ResourceId FROM SMS_R_System WHERE NetbiosName ='" & strMachine & "'")
strNewResourceID = 0
For each insNewResource in colNewResourc
es
strNewResourceID = insNewResourc
e.ResourceID
Next
'if one exists crate a collection rule
If strNewResourceID <> 0 then
Set instDirectRule = objSMS.Get(
"SMS_CollectionRuleDirect").SpawnInstance_ ()
instDirectRule.ResourceClassName
= "SMS_R_System"
instDirectRule.ResourceID = strN
ewResourceID
instDirectRule.RuleName = "Findr
es - Replaces " & strResource
instColl.AddMembershipRule instD
irectRule , SMSContext
instColl.RequestRefresh False
wscript.echo(strMachine & " Adde
d to " & Instcoll.Name)
Else
'otherwise display error
wscript.echo(strMachine & " Not
Found")
end If
'next line
Wend
Else
'if file not found
wscript.echo ("Can't Open " & strfile)
end if
end if
end if
end if

Das könnte Ihnen auch gefallen