[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4981
  • Last Modified:

Add multiple TCP/IP Printer ports at once using Powershell

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
augustkrys
Asked:
augustkrys
  • 2
1 Solution
 
Rob StoneCommented:
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
 
augustkrysAuthor Commented:
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
 
Rob StoneCommented:
Glad it helped and it looks like you've done well with the 2008 script too :)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now