Public/New-specPrinterObject.ps1

function New-specPrinterObject {
    <#
    .SYNOPSIS
        Returns an instance of the Printer object.
 
    .DESCRIPTION
        This function creates and returns an instance of the Printer class, allowing users to manage printer drivers, ports, and printers through object-oriented methods.
 
    .PARAMETER Name
        The name of the printer. Defaults to $null if not specified.
 
    .PARAMETER Driver
        The name of the driver associated with the printer. Defaults to $null if not specified.
 
    .PARAMETER PortName
        The name of the port associated with the printer. Defaults to $null if not specified.
 
    .PARAMETER PrinterHostAddress
        The host address of the printer for port configuration. Defaults to $null if not specified.
 
    .EXAMPLE
        # Instantiate with full parameters for printer management
        $printer = New-specPrinterObject -Name 'OfficePrinter' -Driver 'HP LaserJet' -PortName 'OfficePort' -PrinterHostAddress '192.168.1.10'
        $printer.AddPrinter()
 
    .EXAMPLE
        # Instantiate with null parameters to use port-related methods ('FindUnassignedTCPIPPorts' and 'RemoveUnassignedTCPIPPorts')
        $printer = New-specPrinterObject
        $printer.FindAndRemoveUnusedTCPIPPorts()
 
    .NOTES
        Author: owen.heaume
        Version: 1.0 - Initial release
                    1.1 - Updated to allow optional parameters for port-related methods
                    1.2 - Assign $null to all parameters by default to allow easy usage of
                          'FindUnassignedTCPIPPorts' and 'RemoveUnassignedTCPIPPorts'
    #>


    param (
        [parameter(Mandatory = $false)]
        [string]$Name = $null,

        [parameter(Mandatory = $false)]
        [string]$Driver = $null,

        [parameter(Mandatory = $false)]
        [string]$PortName = $null,

        [parameter(Mandatory = $false)]
        [string]$PrinterHostAddress = $null
    )

    # Create and return an instance of the Printer class
    return [Printer]::new($Name, $Driver, $PortName, $PrinterHostAddress)
}