Link to home
Start Free TrialLog in
Avatar of augustkrys
augustkrys

asked on

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 ?
ASKER CERTIFIED SOLUTION
Avatar of Rob Stone
Rob Stone
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of augustkrys
augustkrys

ASKER

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()
}
Glad it helped and it looks like you've done well with the 2008 script too :)