Solved

Add multiple TCP/IP Printer ports at once using Powershell

Posted on 2014-01-15
3
3,647 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
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Rob Stone earned 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

785 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