Scripts/Get-PCPrinter.ps1

Function Get-PCPrinter {

    <#
 
    .SYNOPSIS
    Get printer information
 
    .DESCRIPTION
    Get printer information
 
    .PARAMETER ComputerName
    The target computer name
 
    .EXAMPLE
    Get-PCPrinter -ComputerName LabPC2024
 
    .NOTES
    N/A
 
    .LINK
    N/A
 
    #>


    [CmdletBinding ()]

    Param (

        [Parameter (Mandatory = $True,
                    ValueFromPipeline = $True,
                    ValueFromPipelineByPropertyName = $True,
                    HelpMessage = 'Enter computer name'
                   )
        ]

        [String[]]$ComputerName

    )

    BEGIN {

        $PrinterStatus = @{

            '1' = 'Other'
            '2' = 'Unknown'
            '3' = 'Idle'
            '4' = 'Printing'
            '5' = 'Warmup'
            '6' = 'Stopped printing'
            '7' = 'Offline'

        }

        Function Show-Output ($Computer, $Values, $Status) {

            [PSCustomObject]@{

                ComputerName = $Computer
                Caption = $Values.Caption
                DriverName = $Values.DriverName
                Location = $Values.Location
                PrinterStatus = $PrinterStatus["$($Values.PrinterStatus)"]
                PrintProcessor = $Values.PrintProcessor
                ShareName = $Values.ShareName
                PortName = $Values.PortName
                Network = $Values.Network
                ServerName = $Values.ServerName
                Status = $Status

            }

        }

    }

    PROCESS {

        ForEach ($Computer In $ComputerName) {

            If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {

                Try {

                    $Data = Get-WmiObject Win32_Printer -ComputerName $Computer | Select-Object *

                    ForEach ($Item In $Data) {

                        Show-Output $Computer.ToUpper() $Item 'Ok'

                    }

                }

                Catch {

                    Show-Output $Computer.ToUpper() $Null $PSItem.Exception.Message

                }

            }

            Else {

                Show-Output $Computer.ToUpper() $Null 'Unreachable'

            }

        }

    }

    END {}

}