Get-PrinterPortInfo.ps1


<#PSScriptInfo
 
.VERSION 1.0.0
 
.GUID 0fca43a0-8d6f-40b6-b753-2c010b79a575
 
.AUTHOR saw-friendship
 
.COMPANYNAME
 
.COPYRIGHT saw-friendship
 
.TAGS Printer PrintServer
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Request Printer and Port info
  
.EXAMPLE
Get-PrinterPortInfo -ComputerName prn-01,prn-02 -PortName 192.168.3.2*
 
ComputerName Name Comment JobCount PrinterStatus Location DriverName Shared ShareName PortName
------------ ---- ------- -------- ------------- -------- ---------- ------ --------- --------
prn-01 RICOH Aficio MP 3350 PCL 6 Printer_33 0 Normal room_402 RICOH Aficio MP 3350 PCL 6 True RICOH_3350_402 192.168.3...
prn-01 HP M475dw PCL 6 Printer_20 0 PaperJam room_305 HP LJ300-400 color MFP M375-M475 PCL 6 True HP M475dw PCL 6 192.168.3...
prn-01 Canon LBP7100_2 Printer_09 0 Normal room_402 Canon LBP7100C/7110C True Canon LBP7100_2 192.168.3.2
prn-01 Canon LBP7100 Printer_07 0 Normal room_309 Canon LBP7100C/7110C True Canon LBP7100 192.168.3...
 
 
#>
 

    param (
        [parameter(Mandatory=$true)][string[]]$ComputerName,
        [string]$PrinterName = '*',
        [string]$PortName = '*'
    )

    Begin {}
    
    Process {
        $ComputerName | % {
            
            $Comp = $_
            $PrinterPort = Get-PrinterPort -ComputerName $Comp | Select-Object -Property Name,Description,Caption,PrinterHostAddress,PrinterHostIP | Group-Object -Property Name -AsHashTable -AsString
        
            Get-Printer -ComputerName $Comp | Select-Object -Property @(
                @{'Name' = 'ComputerName'; 'Expression' = {$Comp}},
                'Name','Comment','JobCount','PrinterStatus','Location','DriverName','Shared','ShareName','PortName',
                @{'Name' = 'PortDescription'; 'Expression' = {$PrinterPort[[string]($_.PortName)].Description}},
                @{'Name' = 'PortCaption'; 'Expression' = {$PrinterPort[[string]($_.PortName)].Caption}},
                @{'Name' = 'PortHostAddress'; 'Expression' = {$PrinterPort[[string]($_.PortName)].PrinterHostAddress}},
                @{'Name' = 'PortHostIP'; 'Expression' = {$PrinterPort[[string]($_.PortName)].PrinterHostIP}}
            ) | ? {$_.Name -like $PrinterName -and $_.PortName -like $PortName}
        }

    }
    
    End {}