Just wanted to post my solution here in case anyone needs it. We recently had to replace a printer that was widely used around the organization. We are using a universal driver for this printer and just needed to update the name of the printer on the machines. Here is the powershell script I came up with.
#Pulls printer name, but it is formatted and not clean. Replace IP with printer IP
$PrinterExtract = wmic printer where "PortName LIKE 'IP%'" GET Name
#removes 'name' string from variable
$PrinterExtract = $PrinterExtract -replace 'Name',''
#removes all empty lines and formatting and creates a new variable
$PrinterName = ($PrinterExtract | Where { $_ -ne "" } | Out-String).Trim()
#pulls printer object
$PrinterObject = Get-Printer -Name $PrinterName
#renames printer. Replace new printer name with the name of new printer
Rename-Printer -InputObject $PrinterObject -NewName "New Printer Name"
I was trying to perform this task without using wmic but could not figure out a way to pull an existing printer's name from an IP. If anyone can provide a more modern solution, it would be appreciated.
Figured it out, if anyone needs it