Add computer to the collection by script
Hi to all I need a script that add PC which already exist and with client (not new PC) to a specific collection I see vbscipt that adding new computers to sccm (http://social.technet.microsoft.com/Forums/en-US/configmgrsdk/thread/157c3192-a9cc-4380-936c-d6926d588ac9), but i need script that adding already existing PC's, so i think in script i need to specify computer name and collection (name or code ?) I don't strong in scripting, so i asking for your help.
March 27th, 2012 6:24am

you can refer the script :- save this code as colladd.vbs ======================================== 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 ("Colladd.vbs server filename collectionID - to add from file to collection") 'wscript.echo ("Colladd.vbs server - to list collectionID's") else on error resume next 'Some error handling strServer=arrArgs(0) 'set variables from command line 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_ProviderLocation where ProviderForLocalSite=True") For Each insSiteDetails In colSiteDetails strSiteCode=insSiteDetails.SiteCode next 'wscript.Echo("Connecting to Root/SMS/site_" & strSiteCode &" on " & strServer) set objSMS=objLocator.ConnectServer(strServer, "root/SMS/site_" + strSiteCode) 'wscript.Echo("Connected") set instColl = objSMS.Get("SMS_Collection.CollectionID="&"""" & strCollID & """") if Instcoll.Name="" then 'check valid collection 'wscript.echo (strCollId &" Not Found") else 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 Next 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 = strMachine instColl.AddMembershipRule instDirectRule , SMSContext instColl.RequestRefresh False 'wscript.echo(strMachine & " Added to " & Instcoll.Name) else 'wscript.echo(strMachine & " Not Found") 'otherwise display error end if WEnd 'next line else 'wscript.echo ("Can't Open " & strfile) 'if file not found end if end if end if ============================================ Create a bat file by adding this command line:- cscript.exe " c:\colladd.vbs" SITECODE "c:\computers.txt" COLLECTION ID
Free Windows Admin Tool Kit Click here and download it now
March 27th, 2012 6:39am

Thank for the reply But , i don't understand how to use it)))) what is computers.txt ? I need specify CollID and ComputerName in script
March 27th, 2012 6:51am

Hi, I normally use this script: How to add a Known/Unknown Computer to a specified collection during OS Deployment http://blogs.msdn.com/b/vinpa/archive/2010/09/01/how-to-add-a-known-unknown-computer-to-a-specified-collection-during-os-deployment.aspx Regards, Jrgen-- My System Center blog ccmexec.com -- Twitter @ccmexec
Free Windows Admin Tool Kit Click here and download it now
March 27th, 2012 6:52am

Thanks for the Reply, Jrgen As I understand it's need to run localy on PC, by TS Is there any possibility to run script from Sccm site server?
March 27th, 2012 7:07am

yes , the computers.txt file contains the list of machines you want to have in the collection.
Free Windows Admin Tool Kit Click here and download it now
March 27th, 2012 7:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics