Quantcast
Channel: Configuration Manager 2007 Operating System Deployment forum
Viewing all articles
Browse latest Browse all 1063

Add Machine to Collection script...

$
0
0

Good day,

I have a child site where we image machine from. Does anyone have a script that they could share that would allow me to run during OSD deploy that would drop the machine being imaged into a collection at the central site?

I've tried modifying the script below. It runs and adds the machine to the collection when run manually outside of OSD, but it never works within OSD deploys. It makes the connection to the site server, but does not add the machine to the collection. 

Set fso = CreateObject("Scripting.FileSystemObject")     

Set objNet = CreateObject("WScript.NetWork")

 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 = 2) Then

  strCollID=arrArgs(1)

 end if

 

strFile=""

 

 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")

 

 if (arrArgs.Count < 2) 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)

  Next

 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")

  else

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

wscript.echo ("Computer Name : " & objNet.ComputerName)

 

     set colNewResources=objSMS.ExecQuery("SELECT ResourceId FROM SMS_R_System WHERE NetbiosName ='" & objNet.ComputerName  & "'") 

     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 & " - colladd"

      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

 

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

  end if

 

 end if

 

end if


Viewing all articles
Browse latest Browse all 1063

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>