Public/Get-specPrintersToInstall.ps1

function Get-specPrintersToInstall {
    <#
    .SYNOPSIS
    Retrieves a list of printers that are not currently installed on the local device based on a provided filter.
 
    .DESCRIPTION
    The Get-specPrintersToInstall function takes a list of printer names as input, checks if they are installed on the local device, and returns the names of printers that are not installed. The printer names are supplied as a comma-separated string and processed via pipeline.
 
    .PARAMETER azPrinterFilterContent
    Specifies a comma-separated string or an array of printer names to be checked against the list of installed printers on the local device. If a printer is not installed, it is added to the list of printers that need to be installed.
 
    .EXAMPLES
    # Example 1: Check which printers from the filter need to be installed
    'Printer1,Printer2,Printer3' | Get-specPrintersToInstall
 
    # Example 2: Using an array of printers
    $printerFilter = 'Printer1,Printer2'
    $printerFilter | Get-specPrintersToInstall
 
    .RETURNS
    The function outputs an array of printer names that are not installed on the local device.
 
    .NOTES
    Author: owen.heaume
    Version: 1.0 - Initial release
    #>



    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string[]]$azPrinterFilterContent
    )

    begin {
        $printersToInstall = @()
        $installedPrinters = Get-Printer
    }

    process {
        $filterPrinters = $_ -split ','

        foreach ($filterPrinter in $filterPrinters) {
            # Check if the current printer is installed on the local device
            if ($installedPrinters.Name -notcontains $filterPrinter) {
                # If not installed, add it to the list of printers to install
                $printersToInstall += $filterPrinter
                Write-Host "$filterPrinter not installed on this device and needs installing" -ForegroundColor DarkYellow
            }
        }
    }

    end {
        $printersToInstall
    }
}