troubleshooting Question

Editing SCCM Colladd.vbs Script

Avatar of AnthonySmithMCP
AnthonySmithMCPFlag for United States of America asked on
.NET ProgrammingMicrosoft DevelopmentMicrosoft Server Apps
3 Comments1 Solution1647 ViewsLast Modified:
I've been using the colladd.vbs script to add systems to a collection. Im trying to get around using a text file. Intstead i want to be able to input the systems throught the command line with the rest of the arguments (server name, collection ID). If anyone can help me with this it will be much appreciated. I added the code below

***I want to be able to input the system name instead of using the text file***

Set fso = CreateObject("Scripting.FileSystemObject")					 

Set arrArgs = WScript.Arguments
if (arrArgs.Count = 0) Then								'Display Blurb
	wscript.echo ("Colladd.vbs v1.0")					
	wscript.echo ("03/06/03 Mark Nunn")
	wscript.echo ("")
	wscript.echo ("Colladd.vbs server filename collectionID - to add from file to collection")
	wscript.echo ("Colladd.vbs server - to list collectionID's")

	on error resume next								'Some error handling

	strServer=arrArgs(0)								'set variables from command line

	if (arrArgs.Count = 3) Then
	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_ProviderLocation where ProviderForLocalSite=True")
	For Each insSiteDetails In colSiteDetails
	wscript.Echo("Connecting to Root/SMS/site_" & strSiteCode &" on " & strServer)
	set objSMS=objLocator.ConnectServer(strServer, "root/SMS/site_" + strSiteCode)

	if (arrArgs.Count < 3) Then							'if not all arguments supplied list colelctions
		set colCollections=objSMS.ExecQuery("select CollectionID, Name from SMS_Collection ORDER BY CollectionID")
		wscript.echo("CollectionID" & vbTab & "Name")
		For Each insCollection In colCollections
			wscript.echo(insCollection.CollectionID & VbTab & insCollection.Name)
	else										'otherwise add from file
		set instColl = objSMS.Get("SMS_Collection.CollectionID="&"""" & strCollID & """")
		if Instcoll.Name="" then						'check valid collection
			wscript.echo (strCollId &" Not Found")
			Set filNames = fso.OpenTextFile(strFile)				'open file of machines
			if  (filNames) then
				While not filNames.AtEndOfStream
					strMachine=filNames.ReadLine				'read each line and find resource ID
					set colNewResources=objSMS.ExecQuery("SELECT ResourceId FROM SMS_R_System WHERE NetbiosName ='" & strMachine & "'")	
					strNewResourceID = 0  				
					For each insNewResource in colNewResources
						strNewResourceID = insNewResource.ResourceID
					if strNewResourceID <> 0 then				'if one exists crate a collection rule
						Set instDirectRule = objSMS.Get("SMS_CollectionRuleDirect").SpawnInstance_ ()
						instDirectRule.ResourceClassName = "SMS_R_System"	
						instDirectRule.ResourceID = strNewResourceID
						instDirectRule.RuleName = "Findres - Replaces " & strResource
						instColl.AddMembershipRule instDirectRule , SMSContext
						instColl.RequestRefresh False
						wscript.echo(strMachine & " Added to " & Instcoll.Name)
						wscript.echo(strMachine & " Not Found")		'otherwise display error
					end if
				WEnd								'next line
				 wscript.echo ("Can't Open " & strfile)				'if file not found
			end if
		end if
	end if
end if
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros