Note: I'm a complete newbie when it comes to Powershell. I haven't even touched it prior to this week.
I need to create a bunch of printer ports (about 400). I found a script that will let me create one at a time and it works flawlessly (http://gallery.technet.microsoft.com/fc636246-c4a4-4aa1-b25d-ce2449b28a05). I have been trying to modify it so that I can import a list of IP addresses from a CSV file and step through the creation of each printer port. This has proven to be easier said then done.
My CSV File looks like this: 192.168.0.1,192.168.0.2, 192.168.0.3, etc etc...
My 'modified' script looks like this:
#Import the CSV list
$IPList=IMPORT-CSV C:\Users\administrator.AD\Downloads\portips.txt
#For testing Lists each item in the above file
#$IPList | FOREACH-OBJECT {$_}
FOREACH ($ip in $IPList) {
print $ip
#From Original Script - $ip = "192.168.0.1"
$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()
}
When I run the original script it creates the one port. When I run my modified, it fails with the following error:
No file to print
Exception calling "Put" with "0" argument(s): "Invali
At C:\Users\administrator.AD\Downloads\test.ps1:30 ch
+ $newport.Put <<<< ()
+ CategoryInfo : NotSpecified: (:) [], M
+ FullyQualifiedErrorId : DotNetMethodException
I'm guessing I'm making a newbie mistake, but I'll be darned if I can find a solution. Anyone able to help me out here? Thanks a bunch!
Jon