Jump to content


  • 0
Darkstarhammer

SCCM HTA to add machines to collection without console

Question

Hi guys hope you can help me

 

found this HTA a wile ago and im trying to adapt it to sccm2012 but my hta skills are bit Noob based, can you help me

 

my mission is to have desktop support to be able to add machine to collections thats basicaly defined by myself.

 

Change this to match your setup

("<SMSSERVERNAME> or <SMSSQLServer>","root\SMS\site_<SMS SITE CODE>")

 

 

Add Computer to Collection.hta

<head>

<title>Add computers to Collection</title>

<body background = "background.jpg">

Add Computer to Collection

<BR>

<hr>

<HTA:APPLICATION

ID="Addcompcol"

APPLICATIONNAME="Addcomputer"

SCROLL="NO"

SINGLEINSTANCE="yes"

WINDOWSTATE="normal"

SYSMENU="no"

>

 

</head>

<script language="VBScript">

 

Sub Closeme

window.close()

end sub

 

Sub Window_Onload

window.moveTo 200,200

window.resizeto 500,500

'width x height

 

end sub

 

</script>

 

<body onload=Window_Onload onkeypress="Checkenter">

<script language="VBScript">

 

 

On error resume next

Set Shell = CreateObject("Wscript.Shell")

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator")

set SWbemServices = SWbemLocator.ConnectServer("<SMSSERVERNAME> or <SMSSQLServer>","root\SMS\site_<SMS SITE CODE>")

If Err.Number Then

Err.Clear

Closeme()

End If

 

sub search()

count=0

if findcomp.value <> "" Then

strQuery = "select * from SMS_CM_RES_COLL_SMS00001 where name like '%"& findcomp.value &"%'"

Set Computers= SWbemServices.ExecQuery(strQuery)

 

strHTML= strHTML & "<select size=""6"" name=""Computerlisting"" multiple width:200"">"

 

for each Computer in Computers

count=count+1

 

if count<50 then

' strHTML= strHTML & "<BR>" & Computer.Name

' msgbox Computer.ResourceID

 

strHTML= strHTML & "<option value="& Computer.ResourceID &">"& Computer.Name &"</option>"

 

End if

Next

 

Output.InnerHTML = strHTML

End if

end sub

 

''''''''''''''''

Sub Checkenter

If window.event.Keycode = 13 Then

search()

End If

End Sub

 

 

 

sub searchcollection()

count=0

if findcoll.value <> "" Then

strQuery = "select * from SMS_Collection where name like '%"& findcoll.value &"%'"

Set Collections= SWbemServices.ExecQuery(strQuery)

 

strHTML= strHTML & "<select size=""6"" name=""Collectionlisting"" multiple width:300"">"

 

for each Collection in Collections

count=count+1

 

if count<50 then

' strHTML= strHTML & "<BR>" & Computer.Name

' msgbox Computer.ResourceID

 

strHTML= strHTML & "<option value="& Collection.CollectionID &">"& Collection.Name &"</option>"

 

End if

Next

strHTML= strHTML & "</select><BR><hr>"

 

strHTML= strHTML & "<input type=""button"" value=""Add to Collection"" onClick=""addcomputers"">"

 

OutputCol.InnerHTML = strHTML

End if

end sub

 

sub addcomputers()

''''''''

For Each Computerselect in Computerlisting.Options

if Computerselect.Selected then

ComputerResourceID = Computerselect.value ' this is the resource value of the computer selected

end if

Next

 

''''''''

For Each Collectionselect in Collectionlisting.Options

if Collectionselect.Selected then

collectionquery = "SMS_Collection.CollectionID='"&Trim(Collectionselect.value)&"'"

Set oCollection = SWbemServices.Get(collectionquery)

Set newDirectRule = SWbemServices.Get("SMS_CollectionRuleDirect").SpawnInstance_

newDirectRule.ResourceClassName = "SMS_R_System"

newDirectRule.ResourceID = ComputerResourceID

' Add the new query rule to a variable.

Set oCollectionRule = newDirectRule

oCollection.AddMembershipRule oCollectionRule

end if

Next

''''''''''

'oCollection.RequestRefresh True

strHTML="Computer has been added!"

Output.InnerHTML = ""

OutputCol.InnerHTML = strHTML

end Sub

 

''''''''''''''''

Sub Checkentercollection

If window.event.Keycode = 13 Then

searchcollection()

End If

End Sub

 

</script>

 

Computer Name Search

<input type="value" style="background-color:#ffb7d6" name="findcomp" size="20" >

<input type="button" value="OK" name="acceptcomp" onClick="search" style="background:red; ">

<BR>

<hr>

<span id="Output"></span>

 

<BR>

<HR>

Collection Name Search

<input type="value" style="background-color:#ffb7d6" name="findcoll" size="20" >

<input type="button" value="OK" name="acceptcoll" onClick="searchcollection" style="background:red; ">

<BR>

<hr>

<span id="OutputCol"></span>

 

 

<input type="button" value="Close Window" name="Closeout" onClick="Closeme" style="background:white; ">

</body>

 

 

 

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.