Solved

Add multiple TCP/IP Printer ports at once using Powershell

Posted on 2014-01-15
3
3,370 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

A procedure for exporting installed hotfix details of remote computers using powershell
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now