?
Solved

Add multiple TCP/IP Printer ports at once using Powershell

Posted on 2014-01-15
3
Medium Priority
?
4,390 Views
Last Modified: 2014-01-20
I am very new to powershell to start.  I need to create multiple printer ports on a single server. I can use

Add -PrinterPort to do this one at a time like:

Add-PrinterPort -PrinterHostAddress 192.168.1.55 -SNMP 1 -SNMPCommunity public -Name tester

How can I use all the same parameters but change the IP ?
0
Comment
Question by:augustkrys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Rob Stone earned 2000 total points
ID: 39783804
I would look at doing  a loop.

Put your IP's in a text file.

$IPAddresses = get-content C:\IP.txt
Foreach ($IP in $IPAddresses){
	Add-PrinterPort -PrinterHostAddress $IP -SNMP 1 -SNMPCommunity public -Name tester
}

Open in new window

0
 

Author Closing Comment

by:augustkrys
ID: 39792374
Sorry this took SO long to accept, of course this worked perfectly! Unfortunately it doesn't work in windows 7 or 2008 R2 , even after upgrading the powershell( which I thought it would.) Those cmdlets are just not supported I guess- I was able to adapt it for those systems using
#Import the CSV list
$IPList=get-content C:\file.csv
#For testing Lists each item in the above file
#$IPList | FOREACH-OBJECT {$_}

FOREACH ($ip in $IPList) {
print $ip
$port = [wmiclass]"Win32_TcpIpPrinterPort"
$port.psbase.scope.options.EnablePrivileges = $true
$newPort = $port.CreateInstance()
$newport.name = "$ip"
$newport.Protocol = 1
$newport.HostAddress = $ip
$newport.PortNumber = "9100"
$newport.SnmpEnabled = $false
$newport.Put()
}
0
 
LVL 15

Expert Comment

by:Rob Stone
ID: 39794138
Glad it helped and it looks like you've done well with the 2008 script too :)
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question