How to deploy applications using an external list? (Full Version)

All Forums >> [Management Products] >> Microsoft Systems Management Server >> SMS 2003



Message


bwoodall -> How to deploy applications using an external list? (5/6/2008 12:12:56 PM)

Is there a way to deploy an application to a external client list like a text or csv file?




bhuffman -> RE: How to deploy applications using an external list? (5/6/2008 12:26:18 PM)

I usually use a script to read the csv or txt file and build and write the query language to a file.  Then paste that query language in the collection.  Here one of my scripts for system name =

OPTION EXPLICIT
DIM strSystemListFile, strQueryFile, strSelectWhat, strAttribute, objFSO
DIM objCQueryFile, objWQueryFile, strLine, objSystemListFile
'Variables
strSystemListFile = "c:\sms\ProxyL.txt"
strQueryFile = "c:\sms\ProxyQ.txt"
strSelectWhat = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = " & chr(34)
strAttribute = chr(34) & " or SMS_G_System_SYSTEM.Name = " & chr(34)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strSystemListFile) Then
Set objSystemListFile = objFSO.OpenTextFile(strSystemListFile, 1)
Else
WScript.Echo strSystemListFile & " does not exist."
WScript.Quit
End If
Set objCQueryFile = objFSO.CreateTextFile(strQueryFile, True)
objCQueryFile.Close
Set objWQueryFile = objFSO.OpenTextFile(strQueryFile, 2)
objWQueryFile.Write strSelectWhat
Do Until objSystemListFile.AtEndOfStream
strLine = objSystemListFile.ReadLine
objWQueryFile.Write strLine
objWQueryFile.Write strAttribute
Loop
objWQueryFile.Close
WScript.Echo "Done!"




rtruss -> RE: How to deploy applications using an external list? (5/6/2008 12:39:45 PM)

Here is one we use, it even creates a log file of what was added to the collection.  Create a text file (the name of the text file must match the name of the collection) with the systems names you want and it will then add those machines to the collection.  It uses an input box for you to enter in the name of the SMS server you want ot use and from there uses a select case to populatethe site doce needed.  I have modified it so it should work for anyone by adding a case smsserver section (the code in green below).

Set WshNetwork = WScript.CreateObject("WScript.Network")
sScriptName = WScript.ScriptFullName
sScriptPathLen = InStrRev(sScriptName,"\",-1,1)
sScriptPath = Left(sScriptName,sScriptPathLen - 1)
sTrimmedScriptName = Right(sScriptName, Len(sScriptName)-2)
nPos1 = Instr(1,sTrimmedScriptName,"\",1)
sSMSServerName = Left(sTrimmedScriptName,nPos1-1)
Dim lLocator, gService, ResID, User, aSystems
Dim CollectRle, oCollectionSet, oCollection
Dim wshShell, oFSO, TrackVar, ts, s
Dim SMSServer, SMSSiteCode
Dim sCollectionName, sListName, nNameLength
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
sInstallName = " SMS Collection Creator"
SMSServer = InputBox("Enter the HostName of the SMS Server to work with." & Vbcrlf & Vbcrlf & "Type 'Quit' to end the program." , sInstallName,sSMSServerName)
Select Case(LCase(SMSServer))
case "bicsms1"
 SMSSiteCode = "bic"
case "capsar"
 SMSSiteCode = "cap"  
case "fdlsms4"
 SMSSiteCode = "fdl"
case "jrzsar"
 SMSSiteCode = "jrz"
case "miasar"
 SMSSiteCode = "mia"
case "stwsms"
 SMSSiteCode = "PAN"
case "pansar"
 SMSSiteCode = "pan"
case "sipsar"
 SMSSiteCode = "sip"
case "stcsar"
 SMSSiteCode = "stc"
case "torsar"
 SMSSiteCode = "tor"
case "tulsar"
 SMSSiteCode = "tul"
case "quit"
 Msg = "Program terminated upon user request."
 title = sInstallName & " Notification!"
 MsgBox msg, 48, title
 wscript.Quit
case "exit"
 Msg = "Program terminated upon user request."
 title = sInstallName & " Notification!"
 MsgBox msg, 48, title
 wscript.Quit
case ""
  Msg = "Program terminated upon user request or" & Vbcrlf & Vbcrlf
  Msg = Msg & "by clicking 'OK' without a hostname or" & Vbcrlf & Vbcrlf
  Msg = Msg & "by clicking 'CANCEL'." & Vbcrlf & Vbcrlf
  title = sInstallName & " Notification!"
 MsgBox msg, 16, title
 wscript.Quit
  case smsserver
   smssitecode = Left(smsserver,3)

case else
 Msg = "I do not recognize " & SMSServer & " as a valid SMS Server."  & Vbcrlf & Vbcrlf
 Msg = Msg & "Please check the name and try again." & Vbcrlf & Vbcrlf
 title = sInstallName & " Notification!"
 MsgBox msg, 16, title
 wscript.Quit   
end select


Set wshShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sScriptName = WScript.ScriptFullName
sScriptPathLen = InStrRev(sScriptName,"\",-1,1)
sScriptPath = Left(sScriptName,sScriptPathLen - 1)

msg = "Please enter the number of the .txt file you want to use." & Vbcrlf & Vbcrlf & "NOTE:  The text file name needs to MATCH the collection you are adding to."& Vbcrlf & Vbcrlf
Dim aFoundFiles()
Redim preserve aFoundFiles(0)
idx = 0
If oFSO.FolderExists(sScriptPath) Then
Set oFolder = oFSO.GetFolder(sScriptPath)
For Each oFile In oFolder.Files
 If LCase(Right(oFile.Name,4))=".txt" Then
  Set f = oFSO.GetFile(sScriptPath & "\" & oFile.Name)
  If f.size > 0 Then
   Redim preserve aFoundFiles(idx)
   aFoundFiles(idx)=oFile.Name
   msg = msg & idx & "  " & aFoundFiles(idx) & Vbcrlf
   idx=idx + 1
  End If
 End If
Next
End If
nListName = InputBox(msg, sinstallname & " Collections List")
msg = ""
If nListName = "" Then WScript.quit
sListName = aFoundFiles(nListName)
sYear = Year(Now)
sMonth = Month(Now)
If len(sMonth) = 1 Then sMonth = "0" & sMonth
sDay = Day(Now)
If len(sDay) = 1 Then sDay = "0" & sDay
sDateLogged =  sYear& "-" & sMonth & "-" & sDay
nHour = Hour(Now)
nMin = Minute(Now)
nSec = Second(Now)
LogFile = sScriptPath & "\" & sDateLogged & "--" & nHour & "." & nMin & "." & nSec & "--" & SMSSiteCode & ".log"
nNameLength = Len(sListName) - 4
sCollectionName = Left(sListName,nNameLength)
Set oLogFile = oFSO.OpenTextFile(LogFile, ForAppending, True)
nCount = 0
If oFSO.FileExists(sScriptPath & "\" & sListName) Then
Set ts = oFSO.OpenTextFile(sScriptPath & "\" & sListName, ForReading)
oLogFile.WriteLine "List file " & sListName & " was opened successfully. " & now

Do While ts.AtEndOfStream <> True
 sRawLine = ts.ReadLine
 sRawLine = trim(sRawLine)
 sRawLine = CStr(sRawLine)
 
 nSpacePos = Instr(sRawLine," ")
 If nSpacePos > 0 Then
  sRawLine = left(sRawLine,nSpacePos - 1)
 End If
 
 nCommaPos = Instr(sRawLine,",")
 If nCommaPos > 0 Then
  sRawLine = left(sRawLine,nCommaPos - 1)
 End If
 nDashPos = Instr(sRawLine,"-")
 If nDashPos > 0 Then
  sRawLine = left(sRawLine,nDashPos - 1)
 End If
 nTabPos = Instr(sRawLine," ")
 If nTabPos > 0 Then
  sRawLine = left(sRawLine,nTabPos - 1)
 End If
  
 If len(sRawLine) > 1 Then
  sMachName = sRawLine
  TrackVar = "False"
  Set lLocator = CreateObject("WbemScripting.SWbemLocator")
  Set gService = lLocator.ConnectServer(SMSServer, "Root\SMS\Site_" & SMSSiteCode)
  Set aSystems = gService.ExecQuery("Select * From SMS_R_System WHERE Name LIKE ""%" + sMachName + "%""")
  For Each system In aSystems
   If UCase(system.name) = UCase(sMachName) Then
    ResID = system.ResourceID
   End If
  Next
  Set aSystems = gService.ExecQuery("Select * From SMS_R_System WHERE Name LIKE ""%" + sMachName + "%""")
  For Each system In aSystems
   If UCase(system.name) = UCase(sMachName) Then
    ResID = system.ResourceID
   End If
  Next
 
 '***************************************************************************
 '**** Start by spawning a blank instance of a collection rule
 '**** Then give that instance the values it needs - this is important
 '***************************************************************************
  Set CollectRle = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
  CollectRle.ResourceClassName = "SMS_R_System"
  CollectRle.RuleName = "ResourceID=" & ResID
  CollectRle.ResourceID = ResID
  Set oCollectionSet = gService.ExecQuery("Select * From SMS_Collection")
 
 '***************************************************************************
 '**** Walk through the enumeration that was returned from the collection .
 '**** Then query above and select the one provided as a parameter
 '***************************************************************************
  TrackVar = "False"
  For Each oCollection In oCollectionSet
   If UCase(oCollection.Name) = UCase(sCollectionName) Then
    oCollection.AddMembershipRule CollectRle
    If Err.Number = 0 Then
     TrackVar = "True"
    End If
   End If
  Next
 
 '***************************************************************************
 '**** Update log file below with success/Failure message, then end script
 '**** Place the path to your own log file here in UNC format. Name it something like ‘*** add2Coll.log
 '***************************************************************************
 
  If TrackVar = "True" Then
   nCount = nCount + 1
   oLogFile.WriteLine sMachName & " was added successfully."
   sSuccessList = sSuccessList & nCount & " - " & sMachName & " was added successfully." & Vbcrlf
  Else
   oLogFile.WriteLine sMachName & " was NOT added successfully."
  End If
'   
 End If
Loop
Else
WScript.echo "File not found: " & sScriptPath & "\" & sListName
WScript.Quit
End If

Set oLogFile = Nothing
Set ts = Nothing
msg = ""
msg = "Script Completed." & Vbcrlf
msg = msg & sCollectionName & Vbcrlf
msg = msg & "Total Number Added: " & nCount & Vbcrlf
msg = msg & sSuccessList
WScript.echo msg
wscript.quit




bwoodall -> RE: How to deploy applications using an external list? (5/6/2008 1:13:27 PM)

Guys thanks for the scripts. I never thought I would have two scripts in the time it took me to eat lunch.

Roger I am getting the following error message.

Line: 96
Char: 1
Error: Type Mismatch: 'nListName'
Code: 800A000D
Source: Microsoft VBScript Runtime error

I looked in the variables and didn't see nListName. Does it need to be added?

Any suggestions?




rtruss -> RE: How to deploy applications using an external list? (5/6/2008 1:43:55 PM)

when you run the script does it show you a list of file names?  I may have forgot to mention that the script and the txt file need to be in the same location unless you change the following line(s).  Change the sscriptpath in the lines below to a location you would store the txt files in.  We keep the script and the txt files in the same folder on our sms server.  I also updated it to let you know if it did not find any collection files to work with.

If oFSO.FolderExists(sScriptPath) Then
Set oFolder = oFSO.GetFolder(sScriptPath)
For Each oFile In oFolder.Files
If LCase(Right(oFile.Name,4))=".txt" Then
Set f = oFSO.GetFile(sScriptPath & "\" & oFile.Name)
If f.size > 0 Then
  Redim preserve aFoundFiles(idx)
  aFoundFiles(idx)=oFile.Name
  msg = msg & idx & "  " & aFoundFiles(idx) & Vbcrlf
  idx=idx + 1
End If
End If
Next
End If

---------------------  updated script -------------------------------


Set WshNetwork = WScript.CreateObject("WScript.Network")
sScriptName = WScript.ScriptFullName
sScriptPathLen = InStrRev(sScriptName,"\",-1,1)
sScriptPath = Left(sScriptName,sScriptPathLen - 1)
sTrimmedScriptName = Right(sScriptName, Len(sScriptName)-2)
nPos1 = Instr(1,sTrimmedScriptName,"\",1)
sSMSServerName = Left(sTrimmedScriptName,nPos1-1)
Dim lLocator, gService, ResID, User, aSystems
Dim CollectRle, oCollectionSet, oCollection
Dim wshShell, oFSO, TrackVar, ts, s
Dim SMSServer, SMSSiteCode
Dim sCollectionName, sListName, nNameLength
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
sInstallName = " SMS Collection Creator"
SMSServer = InputBox("Enter the HostName of the SMS Server to work with." & Vbcrlf & Vbcrlf & "Type 'Quit' to end the program." , sInstallName,sSMSServerName)
Select Case(LCase(SMSServer))
case "bicsms1"
 SMSSiteCode = "bic"
case "capsar"
 SMSSiteCode = "cap"  
case "fdlsms4"
 SMSSiteCode = "fdl"
case "jrzsar"
 SMSSiteCode = "jrz"
case "miasar"
 SMSSiteCode = "mia"
case "stwsms"
 SMSSiteCode = "PAN"
case "pansar"
 SMSSiteCode = "pan"
case "sipsar"
 SMSSiteCode = "sip"
case "stcsar"
 SMSSiteCode = "stc"
case "torsar"
 SMSSiteCode = "tor"
case "tulsar"
 SMSSiteCode = "tul"
case "quit"
 Msg = "Program terminated upon user request."
 title = sInstallName & " Notification!"
 MsgBox msg, 48, title
 wscript.Quit
case "exit"
 Msg = "Program terminated upon user request."
 title = sInstallName & " Notification!"
 MsgBox msg, 48, title
 wscript.Quit
case ""
  Msg = "Program terminated upon user request or" & Vbcrlf & Vbcrlf
  Msg = Msg & "by clicking 'OK' without a hostname or" & Vbcrlf & Vbcrlf
  Msg = Msg & "by clicking 'CANCEL'." & Vbcrlf & Vbcrlf
  title = sInstallName & " Notification!"
 MsgBox msg, 16, title
 wscript.Quit
'  case smsserver
'    smssitecode = Left(smsserver,3)
case else
 Msg = "I do not recognize " & SMSServer & " as a valid SMS Server."  & Vbcrlf & Vbcrlf
 Msg = Msg & "Please check the name and try again." & Vbcrlf & Vbcrlf
 title = sInstallName & " Notification!"
 MsgBox msg, 16, title
 wscript.Quit   
end select


Set wshShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sScriptName = WScript.ScriptFullName
sScriptPathLen = InStrRev(sScriptName,"\",-1,1)
sScriptPath = Left(sScriptName,sScriptPathLen - 1)

msg = "Please enter the number of the .txt file you want to use." & Vbcrlf & Vbcrlf & "NOTE:  The text file name needs to MATCH the collection you are adding to."& Vbcrlf & Vbcrlf
Dim aFoundFiles()
Redim preserve aFoundFiles(0)
idx = 0
notfound = 0
If oFSO.FolderExists(sScriptPath) Then
Set oFolder = oFSO.GetFolder(sScriptPath)
For Each oFile In oFolder.Files
 If LCase(Right(oFile.Name,4))=".txt" Then
  Set f = oFSO.GetFile(sScriptPath & "\" & oFile.Name)
  If f.size > 0 Then
   Redim preserve aFoundFiles(idx)
   aFoundFiles(idx)=oFile.Name
   msg = msg & idx & "  " & aFoundFiles(idx) & Vbcrlf
   idx=idx + 1
  else
       notfound = notfound + 1
  End If
 else
     notfound = notfound + 1
 End If
Next
if notfound > 0 then  WshShell.Popup "No collection files to work with." &vbcrlf&vbcrlf&"Make sure your file name is correct and try again.",30, sInstallName & " Notice", 48
wscript.quit
End If
nListName = InputBox(msg, sinstallname & " Collections List")
msg = ""
If nListName = "" Then WScript.quit
sListName = aFoundFiles(nListName)
sYear = Year(Now)
sMonth = Month(Now)
If len(sMonth) = 1 Then sMonth = "0" & sMonth
sDay = Day(Now)
If len(sDay) = 1 Then sDay = "0" & sDay
sDateLogged =  sYear& "-" & sMonth & "-" & sDay
nHour = Hour(Now)
nMin = Minute(Now)
nSec = Second(Now)
LogFile = sScriptPath & "\" & sDateLogged & "--" & nHour & "." & nMin & "." & nSec & "--" & SMSSiteCode & ".log"
nNameLength = Len(sListName) - 4
sCollectionName = Left(sListName,nNameLength)
Set oLogFile = oFSO.OpenTextFile(LogFile, ForAppending, True)
nCount = 0
If oFSO.FileExists(sScriptPath & "\" & sListName) Then
Set ts = oFSO.OpenTextFile(sScriptPath & "\" & sListName, ForReading)
oLogFile.WriteLine "List file " & sListName & " was opened successfully. " & now

Do While ts.AtEndOfStream <> True
 sRawLine = ts.ReadLine
 sRawLine = trim(sRawLine)
 sRawLine = CStr(sRawLine)
 
 nSpacePos = Instr(sRawLine," ")
 If nSpacePos > 0 Then
  sRawLine = left(sRawLine,nSpacePos - 1)
 End If
 
 nCommaPos = Instr(sRawLine,",")
 If nCommaPos > 0 Then
  sRawLine = left(sRawLine,nCommaPos - 1)
 End If
 nDashPos = Instr(sRawLine,"-")
 If nDashPos > 0 Then
  sRawLine = left(sRawLine,nDashPos - 1)
 End If
 nTabPos = Instr(sRawLine," ")
 If nTabPos > 0 Then
  sRawLine = left(sRawLine,nTabPos - 1)
 End If
  
 If len(sRawLine) > 1 Then
  sMachName = sRawLine
  TrackVar = "False"
  Set lLocator = CreateObject("WbemScripting.SWbemLocator")
  Set gService = lLocator.ConnectServer(SMSServer, "Root\SMS\Site_" & SMSSiteCode)
  Set aSystems = gService.ExecQuery("Select * From SMS_R_System WHERE Name LIKE ""%" + sMachName + "%""")
  For Each system In aSystems
   If UCase(system.name) = UCase(sMachName) Then
    ResID = system.ResourceID
   End If
  Next
  Set aSystems = gService.ExecQuery("Select * From SMS_R_System WHERE Name LIKE ""%" + sMachName + "%""")
  For Each system In aSystems
   If UCase(system.name) = UCase(sMachName) Then
    ResID = system.ResourceID
   End If
  Next
 
 '***************************************************************************
 '**** Start by spawning a blank instance of a collection rule
 '**** Then give that instance the values it needs - this is important
 '***************************************************************************
  Set CollectRle = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
  CollectRle.ResourceClassName = "SMS_R_System"
  CollectRle.RuleName = "ResourceID=" & ResID
  CollectRle.ResourceID = ResID
  Set oCollectionSet = gService.ExecQuery("Select * From SMS_Collection")
 
 '***************************************************************************
 '**** Walk through the enumeration that was returned from the collection .
 '**** Then query above and select the one provided as a parameter
 '***************************************************************************
  TrackVar = "False"
  For Each oCollection In oCollectionSet
   If UCase(oCollection.Name) = UCase(sCollectionName) Then
    oCollection.AddMembershipRule CollectRle
    If Err.Number = 0 Then
     TrackVar = "True"
    End If
   End If
  Next
 
 '***************************************************************************
 '**** Update log file below with success/Failure message, then end script
 '**** Place the path to your own log file here in UNC format. Name it something like ‘*** add2Coll.log
 '***************************************************************************
 
  If TrackVar = "True" Then
   nCount = nCount + 1
   oLogFile.WriteLine sMachName & " was added successfully."
   sSuccessList = sSuccessList & nCount & " - " & sMachName & " was added successfully." & Vbcrlf
  Else
   oLogFile.WriteLine sMachName & " was NOT added successfully."
  End If
'   
 End If
Loop
Else
WScript.echo "File not found: " & sScriptPath & "\" & sListName
WScript.Quit
End If

Set oLogFile = Nothing
Set ts = Nothing
msg = ""
msg = "Script Completed." & Vbcrlf
msg = msg & sCollectionName & Vbcrlf
msg = msg & "Total Number Added: " & nCount & Vbcrlf
msg = msg & sSuccessList
WScript.echo msg
wscript.quit




bwoodall -> RE: How to deploy applications using an external list? (5/6/2008 2:12:03 PM)

Yes I placed both the script and the text file on the root of c on the SMS server and created a collection in SMS name Test. The script ask for the SMS server name then it list any text files. My text file is Test.txt so enter it and hit Ok that is when it throws the error.




rtruss -> RE: How to deploy applications using an external list? (5/6/2008 3:01:05 PM)

I have been looking at my responses to you and I also noticed I forgot to tell you that you need to enter each system name on its own line.  So sorry about that, just got back from MMS/Vegas and I am still not focused yet.  I have also gone through and tested the code and cannot reproduce the error.  Is your site code part of your server name?  That may be an issue with the code as it sits.

try replacing
' case "bicsms1"
'  SMSSiteCode = "bic"
with
case "your sms server name"
 SMSSiteCode = "your site code"
in the script and see what happens.

i noticed you had it on the root of c  are you executing it dirctly from the server?  I have not tried this as I usually do everything from my laptop and use a unc path.

Also what version of SMS are you using?  I know this should work with SMS 2003 R2 but We do not have SCCM yet so I cannot vouch for it at this time, soon though I hope.




bwoodall -> RE: How to deploy applications using an external list? (5/6/2008 3:25:09 PM)

Before I made the "case" change I used the server IP. Now it sees the server name also the site code is different from the server name. The computers are listed in a single column and I also moved both files to a folder on the d drive of the server. I have ran it both from the server and from a unc path and receive the same error. SMS 2003 SP3

Line: 96
Char: 1
Error: Type Mismatch: 'nListName'
Code: 800A000D
Source: Microsoft VBScript Runtime error




bwoodall -> RE: How to deploy applications using an external list? (5/6/2008 4:01:05 PM)

rtruss

I figured it out and it was so difficult. [:@] Just enter the number next to the file name instead of the file name. Works wonderful now. Thanks




rtruss -> RE: How to deploy applications using an external list? (5/6/2008 4:14:26 PM)

Never thought to ask you if that was what was happening.  Glad to har you got it working!!!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.2109375