I have always been annoyed by the seven steps it takes to find a printer’s IP in the Printer Management MMC. I even reached out on TechNet about this and was told that it was a limitation of the MMC. For a long time, I would look at the extended view window to get the IP. Some printers show their IP when you use Extended View but many don’t.
With a bit of PowerShell, you can populate the Comment attribute with the IP address of the Printer. This script uses the Print Management module which was introduced on Windows 2012 servers. If you want to run it on Windows 8+, you just need to install the RSAT tools.
1 2 3 4 5 6 7 |
$PrintServer = "YOUR-PRINT-SERVER.DOMAIN.Local" $Printers = get-printer -ComputerName $PrintServer foreach ($Printer in $Printers){ Set-Printer -Name $Printer.name -ComputerName $PrintServer -Comment $Printer.PortName } |
The only thing you will need to specify in this script is your print server name in line 1. Set this script to run on a regular basis so that your data is current. Finally, select the View button – Add/Remote Columns and add the Comment attribute to the Displayed columns row.
You can now see the printer’s IP in Print Management without any additional steps. If you are curious, you can read other printer management tips (including why you should set a location) here. If you have any other tips for printer management, let me know in the comments below.
I have been looking for this for years!!!! This is amazing, thanks so much!!!!!
$PrintServer = “yourprintserver.local”
$Printers = get-printer -ComputerName $PrintServer
foreach ($Printer in $Printers){
$PrinterPorts = get-printerport -ComputerName $PrintServer
#write-host $Printer.PortName
foreach ($PrinterPort in $PrinterPorts)
{
if($Printer.PortName -eq $PrinterPort.Name)
{
Write-host $Printer.Name “: ” $PrinterPort.PrinterHostAddress
Set-Printer -Name $Printer.name -ComputerName $PrintServer -Comment $PrinterPort.PrinterHostAddress
}
}
}
Nah. That didn’t work… Then again, in my experience, Powershell rarely if ever does.
get-printer : An error occurred while performing the specified operation. See the error details for more information.
At line:2 char:13
+ $Printers = get-printer -ComputerName $PrintServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Get-Printer], CimException
+ FullyQualifiedErrorId : HRESULT 0x8007007b,Get-Printer
Extremely helpful error message. I wonder why they even bother at all. Run on Windows 10 Pro x64 with RSAT installed.
Hey Jason – can you run get-printer -computername (enter your print server name here)?
Printer name error, the Hresult tells it all.
Genius!
Thanks for sharing!
I am glad to see that I wasn’t the only one frustrated with this! 🙂
Great idea! I have printer names with department name in square brackets,
for example: [DG] HP Color LaserJet 400 M475dn MFP
I got script error:
Exception calling “FilterByProperty” with “4” argument(s): “The specified wildcard character pattern is not valid: [DG] HP Color LaserJet 400 M475dn MFP”
At :line:1376 char:9
+ $ <<<< __cmdletization_queryBuilder.FilterByProperty('Name', $__cmdletization_values, $true, 'Default')
I was able to duplicate your issue and I find it very strange. I tried quoting the variable – establishing a new variable. For kicks, I even tried get-printer with the printer name. It would not return anything for me that way as well.
I’ve found that you need to escape the square brackets so:
[DG
] HP Color LaserJet 400 M475dn MFPhmm it seems the backticks “
” are being swallowed by the site….
[DG
] HP Color LaserJet 400 M475dn MFP
When I tried running this script I get an error that “Get-Printer” is not recognized as the name of a cmdlet or function. Do I need to load a specific PowerShell Library first?
You need Powershell Version 4.0 and from what I’ve found on Google it only works with Powershell 4.0 on Windows 8/Server 2012/2012 R2
Joseph, you should probably make note of this in your article if its true.
You are right Dave – it does use the Print management module which was introduced in Windows Server 2012. I noted that in the post as well.
Make sure you have access to the Print management module – this was introduced in Windows Server 2012.
I had the same problem. Turns out the Get-Printer cmdlet is 2012 and windows 8.1 only. Even though my Printerserver is a 2008r2 box I ran the script from my 8.1 workstation and it then worked.
This is awesome. I will be putting this in production ASAP!
🙂 It is the simple things that make such a difference.
Hello.
This will return “Portname”. Usually we configure portname using printer’s hostname, not IP.
So we need to resolve Portname first:
$PrintServer = “YOUR-PRINT-SERVER.DOMAIN.Local”
$Printers = get-printer -ComputerName $PrintServer
foreach ($Printer in $Printers){
$ip = [System.Net.Dns]::GetHostAddresses($Printer.PortName)
Set-Printer -Name $Printer.name -ComputerName $PrintServer -Comment $ip.IPAddressToString
}
I really like this Altimar! I didn’t even think about the portname being different for some people.
Thanks!. After running a combo of both scripts It caught all of my different printers.
No problem Andy! Glad you have it up and running now!