Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pull variable from text file

Status
Not open for further replies.

Devhip

IS-IT--Management
Dec 9, 2009
2
US

I have a simple script I am using to disable SNMP on TCP/IP printer ports. Problem is that I have about 400 ports to config so scripting one port at a time is hardly faster than changing the property in the printer port dialog box. Here's the script:

Set objWMIService = GetObject("winmgmts:")
Set objPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objPort.Name = "IP_192.168.1.25"
objPort.Protocol = 1
objPort.HostAddress = "192.168.1.25"
objPort.PortNumber = "9999"
objPort.SNMPEnabled = False
objPort.Put_

What I need to do is either:

A) Turn off SNMP for all TCP/IP ports on the box (instead of specifying each IP port)

or....

B) Pull the port info from a text file in which I can copy/paste a list of IP ports to apply the script to. Problem here is that it requires objPort.Name and objPort.HostAddress (which is preceeded by IP_).

I'm a total scripting hack but trying to learn. Any help appreciated!

 
Correct me if I'm wrong but it sounds like you want to modify upto 400 port on a single computer. Each port requires a Name and HostAddress. The Name is made of of "IP_" and the HostAddress. If these names and IPs were in a text file, you would like to information read and the port changed accordingly.

Given:

portinfo.txt (Name, HostAddress)
--------------------------------
192.168.1.25
192.168.1.67
192.168.1.123
.
.
.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile("portinfo.txt", 1)

'loop through file, reading one line at a time.
do while not (objFile.AtEndOfStream)
   strLine = trim(objFile.ReadLine)
   if (strLine <> "") then
      set objPort = objWMI.GetObject("Win32_TCPIPPrinterPort").SpawnInstance
      objPort.Name = "IP_" & strLine
      objPort.HostAddress = strLine
      .
      .
   end if
loop

This should at least get you started

-Geates
-Geates
 

Ah, nice. This worked perfectly. I tweaked a little and tested and it worked great. Here's the end result:

________________________________
rem ** Disable SNMP on list of TCP/IP printer ports
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile("portinfo.txt", 1)

'loop through file, reading one line at a time.
do while not (objFile.AtEndOfStream)
strLine = trim(objFile.ReadLine)
if (strLine <> "") then
Set objWMIService = GetObject("winmgmts:")
Set objPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objPort.PortNumber = "9999"
objPort.Name = "IP_" & strLine
objPort.HostAddress = strLine
objPort.SNMPEnabled = False
objPort.Put_
end if
loop
_______________________________________

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top