Thursday, June 10, 2010

Set Printer Share Comment to the Port Name With IP Address

So as an update to an earlier post on adding the port name to the comments of a print queue on a Server 2003/2008/2008 R2 box, below is an update script that will add both the port name and the IP address or DNS host name associated with a given port.


$printersWMI = Get-WMIObject -Class "Win32_Printer" -NameSpace "root\cimv2" -computername "."
$portsWMI = Get-WMIObject -Class "Win32_TCPIPPrinterPort" -NameSpace "root\cimv2" -computername "."
$ports = @{}
ForEach($port in $portsWMI){
$ports[$port.name] = $port.HostAddress
}

ForEach($printer in $printersWMI){
$printer.Comment = $printer.PortName + "`r`n" + $ports[$printer.PortName]
$printer.Put()
}



No comments: