none
Change local ip printer ports RRS feed

  • Question

  • I am wanting a script that will import a csv of old and new ip addresses and if the old ip matches a currently installed ip it will change it to the new address and set the printer to the new port.  Something like this:

    $testcsv = import-csv c:\test.csv
     
     
     foreach($test in $testcsv)
     
       {
     
       $OldIP = $test.OldIP
     
       $NewIP = $test.NewIP
       }
      
    If (Get-PrinterPort -Name -eq "$OldIP")
    {Add-PrinterPort -Name "$NewIP" -PrinterHostAddress $NewIP
    Get-Printer | Where-Object { $_.PortName -eq "$OldIP"} | Set-Printer -PortName "$NewIP"
    Remove-PrinterPort -Name "$OldIP"}


    Friday, February 12, 2016 11:52 PM

Answers

  • Almost -

    This is closer to something that will work:

    import-csv c:\test.csv |
    	ForEach-Object{
    		Try{
    			if($p=Get-Printer -Name $_.OldIP -Ex 0){
    				Add-PrinterPort -Name $_.NewIP -PrinterHostAddress $_.NewIP -PortNumber 9100 -ea Stop
    				$p| Set-Printer -PortName $_.NewIP -ea Stop
    				Remove-PrinterPort -Name $_.OldIP -ea Stop
    			}
    		}
    		Catch{
    			Throw $_
            }
        }


    \_(ツ)_/


    • Edited by jrv Wednesday, February 17, 2016 7:20 AM
    • Marked as answer by BrianConniff Saturday, February 20, 2016 7:22 AM
    Saturday, February 13, 2016 12:07 AM

All replies

  • Almost -

    This is closer to something that will work:

    import-csv c:\test.csv |
    	ForEach-Object{
    		Try{
    			if($p=Get-Printer -Name $_.OldIP -Ex 0){
    				Add-PrinterPort -Name $_.NewIP -PrinterHostAddress $_.NewIP -PortNumber 9100 -ea Stop
    				$p| Set-Printer -PortName $_.NewIP -ea Stop
    				Remove-PrinterPort -Name $_.OldIP -ea Stop
    			}
    		}
    		Catch{
    			Throw $_
            }
        }


    \_(ツ)_/


    • Edited by jrv Wednesday, February 17, 2016 7:20 AM
    • Marked as answer by BrianConniff Saturday, February 20, 2016 7:22 AM
    Saturday, February 13, 2016 12:07 AM
  • You're awesome thank you.

    I'll give somebody a dollar if they can show me how to write this in vb script...


    Wednesday, February 17, 2016 6:53 AM