Blog
By Will Southerland on 7/31/2010 4:59:02 PM • Rank (3933) • Views 4180
2

2

I was intrigued by a question someone asked in the following Microsoft forum:

Create Direct Membership Based on PC Serial Number
http://social.technet.microsoft.com/Forums/en/configmgrgeneral/thread/6f998293-c7b5-484c-981d-55723c9bb0ea

I opened up the AddColl.hta file used by Greg Ramsey's SCCM Right-Click tool and noticed how it queried for resourceIDs based on computer names on line 113:

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

I made a copy of the hta and saved it as AddCollBySerial.hta and modified line 113 to read:

set colNewResources=objSMS.ExecQuery("select distinct SMS_R_System.ResourceId, SMS_R_System.Name from SMS_R_System inner join SMS_G_System_PC_BIOS on SMS_G_System_PC_BIOS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_PC_BIOS.SerialNumber = '" & strSerialNumber & "'")

I did a Replace all to change strMachine to strSerialNumber for conventions sake. I also changed:

strNewResourceID = 0
For each insNewResource in colNewResources
strNewResourceID = insNewResource.ResourceID
Next

to:

strNewResourceID = 0
strNewResourceName = ""
For each insNewResource in colNewResources
strNewResourceID = insNewResource.ResourceID
strNewResourceName = insNewResource.Name
Next

so that I could change:

instDirectRule.RuleName = strResource

to:

instDirectRule.RuleName = strNewResourceName

so that the rules wouldn't show up as blank.

I made some other purely cosmetic modifications to the HTML to get rid of the Dell logo at the top left and modified the window label and button label to have the "by Serial Number" on them. I adjusted the text area width to accommodate long serial numbers and adjusted the initial window height to better hide the unsuccessful attempts area that pops up after you run the app.

Finally, I added the following XML just below line 2 to the Collection Tools.xml file located in AdminUI\XmlStorage\Extensions\Actions\dbb315c3-1d8b-4e6a-a7b1-db8246890f59 (note, you will need to change the entry in FilePath in your environment):

<ActionDescription Class="Executable" DisplayName="Add Systems to a Collection by Serial" MnemonicDisplayName="Add Systems a Collection by Serial" Description = "Add Systems to a Collection by Serial"> <Executable> <FilePath>G:\SCCM\AdminUI\XMLStorage\Tools\AddCollbySerial.hta<!--FilePath> <Parameters>/ss:##SUB:__SERVER## /sn:##SUB:__Namespace## /coll:##SUB:COLLECTIONID## /CollName:##SUB:Name##<!--Parameters> <!--Executable> <!--ActionDescription>

Close and open the Configuration Manager Admin Console, Right-Click a collection and you get:

ConfigMgr Collection Tools - Add Systems to a Collection by Serial

Add PCs to Collection by Serial Number HTA pre

Full source for AddCollbySerial.hta below:

<html>
<head>
<title>SMS -- Add PCs to Collection by Serial</title>
<HTA:APPLICATION
ID="oAddColl"
APPLICATIONNAME="AddToCollbySerial"
BORDER = "thick"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
SCROLL="no"
SCROLLFLAT="no"
VERSION="1.0"
INNERBORDER="yes"
BORDERSTYLE="normal"
>
</head>

<style>
BODY
{
background-color: buttonface;
font-family: Helvetica;
font-size: 8pt;
margin-top: 10px;
margin-left: 10px;
margin-right: 10px;
margin-bottom: 10px;
}

..button
{
font-family: Helvetica;
font-size: 8pt;
width: 35px;
}

textarea
{
font-family: arial;
font-size: 8pt;
margin-left: 3px;
width: 300px;
}

select
{
font-family: arial;
font-size: 8pt;
width: 300px;
margin-left: 0px;
}

</style>

<script language="vbscript">
'''''' Created by Greg Ramsey with the help of
'''''' posts/articles on myITforum -- Special thanks to Dan Thompsen for his ParseCmdLine procedure!
'''''' Stolen from Greg Ramsey and "modified" by Will Southerland to do serials "Thanks Greg!"
Dim strServer
Dim strSite
Dim strCollectionID
Dim strCollectionName

Sub ProcessComputers()
self.ResizeTo 1,1
Set objDialogWindow = window.Open("about:blank","ProgressWindow","height=15,width=250,left=300,top=300,status=no,titlebar=no,toolbar=no,menubar=no,location=no,scrollbars=no")
objDialogWindow.Focus()
objDialogWindow.ResizeTo 250,15
objDialogWindow.document.body.style.fontFamily = "Helvetica"
objDialogWindow.document.body.style.fontSize = "11pt"
objDialogWindow.document.writeln "<html><body>Adding PCs to " & collName.Value & " </body></html>"
objDialogWindow.document.title = "Please wait."
objDialogWindow.document.body.style.backgroundColor = "dodgerblue"
objDialogWindow.document.body.style.borderStyle = "none"
objDialogWindow.document.body.style.marginTop = 15
AddToCollection ComputerList.value, CollID.value, ss.Value, objDialogWindow
objDialogWindow.Close()
self.ResizeTo 450,550
end sub

Sub Window_Onload
self.ResizeTo 450,380
self.MoveTo 20,20
'Get the command line args
ParseCmdLine

ComputerList.Focus()
end sub

Sub ResetForm
computerlist.value = ""
results.value = ""
ComputerList.Focus()
end Sub

Sub AddToCollection(strList, strCollID, strServer, DialogWindow)
arrList = split(strList,vbcrlf)    'split the list by CR/LF
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSMS = objLocator.ConnectServer(strServer, "Root/SMS")                    'connect to sms
objSMS.Security_.ImpersonationLevel = 3
set colSiteDetails=objSMS.ExecQuery("select Machine, SiteCode from SMS_ProviderLocation where ProviderForLocalSite=True")

For Each insSiteDetails In colSiteDetails
strSiteCode=insSiteDetails.SiteCode
next
set objSMS=objLocator.ConnectServer(strServer, "root/SMS/site_" & strSiteCode)
set instColl = objSMS.Get("SMS_Collection.CollectionID=""" & strCollID & """")

if Instcoll.Name="" then                                                'check valid collection
end if

for each strSerialNumber in arrList
DialogWindow.document.Body.InnerHTML =  "Querying " & strSerialNumber ' & "<br>"
set colNewResources=objSMS.ExecQuery("select distinct SMS_R_System.ResourceId, SMS_R_System.Name from SMS_R_System inner join SMS_G_System_PC_BIOS on SMS_G_System_PC_BIOS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_PC_BIOS.SerialNumber = '" & strSerialNumber & "'")

strNewResourceID = 0
strNewResourceName = ""
For each insNewResource in colNewResources
strNewResourceID = insNewResource.ResourceID
strNewResourceName = insNewResource.Name
Next
if strNewResourceID <> 0 then                           'if one exists create collection rule
Set instDirectRule = objSMS.Get("SMS_CollectionRuleDirect").SpawnInstance_ ()
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = strNewResourceID
instDirectRule.RuleName = strNewResourceName
instColl.AddMembershipRule instDirectRule , SMSContext
instColl.RequestRefresh False
tmpCount = tmpCount + 1
else
if len(strSerialNumber) => 1 then
results.value = results.value & strSerialNumber & vbCRLF
end if
end if
next
instColl.RequestRefresh True
'cleanup
Set objLocator = nothing
Set objSMS = nothing
Set colSiteDetails = nothing
Set instColl = nothing
Set colNewResources = nothing
Set strNewResourceID = nothing
Set instDirectRule = nothing
'msgbox "complete"
end sub

Sub ParseCmdLine()

Dim strCommandLine
Dim Item

strCommandLine = oAddColl.commandLine
If Instr(1, strCommandLine, "/", 1) = 0 Then
Exit Sub
End If

strCommandLine = Mid(strCommandLine, Instr(strCommandLine, "/") - 1)
arrCommandLine = Split(strCommandLine, "/", -1, 1)

For Each Item in arrCommandLine
arrParameter = Split(Item, ":")
Select Case LCase(arrParameter(0))

Case "ss"
strServer = Trim(UCase(arrParameter(1)))
ss.Value = strServer
'msgbox "found " & strServer

Case "sn"
strSite = Trim(UCase(arrParameter(1)))
sn.Value = strSite
'msgbox "found " & strSite

Case "coll"
strCollectionID = Trim(arrParameter(1))
collID.Value =    strCollectionID
'msgbox "found " & strCollectionID

Case "collname"
strCollectionName = Trim(arrParameter(1))
collName.Value =    strCollectionName
'msgbox "found " & strCollectionName

Case Else 'We shouldn't get here
End Select
Next
End Sub
</script>

<body style="background-color: #000000">
<center>
<h2 font face="Georgia, Garamond, Times New Roman" color="#FF0000">
<font color="#FFFFFF">
Add PCs to Collection by Serial Number</font></h2>
<font color="#FFFFFF"><font face="Verdana" size="3">Collection Name</font><font face="Verdana" size="2">:</font>  <INPUT TYPE="text" NAME="CollName" READONLY>
<br>
<INPUT TYPE="hidden" NAME="ss">
<INPUT TYPE="hidden" NAME="sn">
<INPUT TYPE="hidden" NAME="CollID">
<font face="Verdana, Tahoma, Arial" size="3">
Enter or Paste Serial Numbers:
</font>
<font face="Verdana, Tahoma, Arial" size="2">
<br>
</font>
<font face="Verdana, Tahoma, Arial" size="3">
<textarea cols="25" rows="10" name=ComputerList ></textarea>
<br>
<br>
<input type="button" value="Add PCs To Collection by Serial" onClick="ProcessComputers()">
<br>
<input type="button" Value="Reset Form" onClick="ResetForm()">
<input type="button" Value="   Exit   " onClick=self.Close()>
<br>
<br>
Unsuccessful attempts:
<br>
<textarea cols="25" rows="10" name=results READONLY></textarea>
</font>
</font>
</center>
</body>
</html>

Comments - Comment RSS


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/34gsryr

Top Contributors
Featured Members
Pete Zerger
Points: 65442
Level: System Center Expert
Tommy Gunn
Points: 42712
Level: System Center Expert
Simon Skinner
Points: 40744
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27434
Level: System Center Expert