myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


Create a collection based on text file??

 
Logged in as: Guest
  Printable Version
All Forums >> [Management Products] >> Microsoft Systems Management Server >> SMS 2003 >> Create a collection based on text file?? Page: [1]
Login
Message << Older Topic   Newer Topic >>
Create a collection based on text file?? - 8/18/2005 9:29:09 AM   
jbabcock


Posts: 219
Score: 4
Joined: 10/16/2003
Status: offline
Hello, does anyone know how to create a collection based on a list (text file) of computer names?

Thanks.
Post #: 1
RE: Create a collection based on text file?? - 8/18/2005 9:41:41 AM  1 votes
lramsdale


Posts: 1068
Score: 44
Joined: 1/23/2004
From: Oxford - UK
Status: offline
yes there is a vbs script called colladd that does exactly this:

quote:

' #################################################################
' #colladd.vbs http://mark.nunn.net #
' # #
' #This adds a list of machine names from a file to a collection. #
' #It can also list all collections on a server. #
' #################################################################
' #M.Nunn 03/06/03 #
' #################################################################
' #Update 04/11/03: Fixed bug with rule name (thanks to Lance #
' #Rissman) #
' #################################################################


Set fso = CreateObject(" Scripting.FileSystemObject" )
strBlurb= " Colladd.vbs v1.1" & VbCrLf & _
" 03/06/03 - Updated 04/11/03 Mark Nunn" & VbCrLf & _
" http://mark.nunn.net" & VbCrLf & _
" Colladd.vbs server filename collectionID - to add from file to collection" & VbCrLf & _
" Colladd.vbs server - to list collectionID' s"

intDisplayLines=30 ' Number of lines to display in each page under Wscript

Set arrArgs = WScript.Arguments
if (arrArgs.Count = 0) Then ' Display Blurb
wscript.echo (strBlurb)
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

strScriptPath = WScript.FullName
Set regEx = New RegExp ' Discover if running from Wscript
regEx.Pattern = " Wscript" ' All display in one go if it is
regEx.IgnoreCase = True ' line by line if it isn' t
booWscript = regEx.test(strScriptPath)

Set objLocator = CreateObject(" WbemScripting.SWbemLocator" )
Set objSMS = objLocator.ConnectServer(strServer, " Root/SMS" ) ' connect to sms
objSMS.Security_.ImpersonationLevel = 3

if not booWscript then 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
if not booWscript then wscript.Echo(" Connecting to Root/SMS/site_" & strSiteCode &" on " & strServer)
set objSMS=objLocator.ConnectServer(strServer, " root/SMS/site_" + strSiteCode)
if not booWscript then wscript.Echo(" Connected" )

if (arrArgs.Count < 3) Then ' if not all arguments supplied list colelctions
set colCollections=objSMS.ExecQuery(" select CollectionID, Name from SMS_Collection ORDER BY Name" )
if not booWscript then
wscript.echo(" CollectionID" & vbTab & " Name" )
else
strOutput=strOutput & " CollectionID" & vbTab & " Name" & VbCrLf
end if
For Each insCollection In colCollections
if not booWscript then
wscript.echo(insCollection.CollectionID & VbTab & insCollection.Name)
else
strOutput=strOutput & insCollection.CollectionID & VbTab & insCollection.Name & VbCrlf
end if
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
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, Name FROM SMS_R_System WHERE NetbiosName =' " & strMachine & " ' " )
strNewResourceID = 0
For each insNewResource in colNewResources
strNewResourceID = insNewResource.ResourceID
strName = insNewResource.Name
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 = strName & " Added by CollAdd.vbs"
instColl.AddMembershipRule instDirectRule , SMSContext
instColl.RequestRefresh False
if not booWscript then
wscript.echo(strName & " Added to " & Instcoll.Name)
else
strOutput=strOutput & strName & " Added to " & Instcoll.Name & VbCrLf
end if
else
if not booWscript then
wscript.echo(strMachine & " Not Found" ) ' otherwise display error
else
strOutput=strOutput & strMachine & " Not Found" & VbCrLf
end if

end if
WEnd ' next line
else
wscript.echo (" Can' t Open " & strfile) ' if file not found
end if

end if
end if
end if
if booWscript and strOutput then ' if running in Wscript display stored output
arrOutput=split(strOutput,VbCrLf)
strOutput=" "
for each strLineout in arrOutput
intCount=intCount+1 ' process each line
' wscript.echo (intCount)
strOutput=strOutput & strLineout & VbCrLf
if intCount = intDisplayLines then
wscript.echo (strOutput) ' and when enough lines for a page display them
strOutput=" "
intCount=0
end if
next
wscript.echo (strOutput)
end if



quote:

Collad.VBS
----------

The colladd vbs script will take a list of machines from a text file and add them into an existing collection. To do this:

1) Create a text file contain a list of machine names to add to the collection. This should be in the format:

Machine1
Machine2
Machine3
...

2) run ' colladd.vbs smserver' where smsserver is the netbios name of your SMS server. This will give you a list of all the collection names and collection id' s. Make a note of the collection ID for the collection you want to add the machines to.

3)run ' CollAdd.vbs SMSserver filename CollectionID' where SMSserver is the name of your SMS server, filename is the file with the list of machines and CollectionID is the ID of the Collection you wish to add the machines to.

Quick Example:

to add three machines to a collection called ' Test Collection' in an SMS server called SMS01

1) create ' machines.txt' containing:

FredPC
BertPC
JohnPC

2) colladd.vbs SMS01

SMS00001 All Systems
SMS00002 All Users
...
S01000FE Test Collection

3) colladd.vbs SMS01 machines.txt S01000FE

FredPC Added to Test Collection
BertPC Added to Test Collection
JohnPC Added to Test Collection

NOTE: This script will behave differently depending on whether it' s running under Cscript or Wscript. When run under Cscript it will display all output a line at a time. Under Wscript it will not display any output until the end of the script, then it will display 30 lines at a time. The script can be configured to display more or less lines to each message in Wscript by changing the line ' intDisplayLines=30' to the required value.

(in reply to jbabcock)
Post #: 2
RE: RE: Create a collection based on text file?? - 8/18/2005 10:22:27 AM   
jbabcock


Posts: 219
Score: 4
Joined: 10/16/2003
Status: offline
Thanks, works great!

(in reply to lramsdale)
Post #: 3
RE: RE: Create a collection based on text file?? - 8/21/2009 2:53:28 PM   
pglyn-williams

 

Posts: 96
Score: 2
Joined: 8/10/2001
From: Toronto, Canada
Status: offline
I've been trying to get our Acquisitions admin to be able to add computers to collections using the colladd script.  My question is, what are the provisional SMS permissions are required for this script?

I've tried adding her with Adminster permission under {All Instances} of Collection, but still doesn't work.  I know this should do the trick, but it isn't working for some reason.

Note: Script works with SMS Admin.

Thanks in advance.


< Message edited by pglyn-williams -- 8/21/2009 2:54:15 PM >


_____________________________

Pierson Glyn-Williams
Systems Management
Region of Peel (HQ)

(in reply to jbabcock)
Post #: 4
RE: RE: Create a collection based on text file?? - 8/23/2009 11:58:25 AM   
skissinger


Posts: 3592
Score: 285
Joined: 9/13/2001
From: Sherry Kissinger
Status: offline
In addition to permissions within the console, since the script is essentially accessing WMI on the SMS primary site server, you will need to ensure that this person's account is in the local group on the server called "SMS Admins". They may or may not also need to be in (i think it's called) DCOM..something or other. DCOM Authenticated users(?) (I'm not in front of a server right now; it's Sunday, this is from memory!)

Since your default SMS ADmin account can use the script, I'm going to assume that you have all the correct firewall ports,etc., open; and it's local permissions to either the server or within the console. So start with the above; and see if that's enough.

_____________________________

mofmaster@myitforum.com
My Blog
Microsoft MVP - ConfigMgr

(in reply to pglyn-williams)
Post #: 5
Page:   [1]
All Forums >> [Management Products] >> Microsoft Systems Management Server >> SMS 2003 >> Create a collection based on text file?? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.359