Public/Get-specIPPrintersNotInFilter.ps1
function Get-specIPPrintersNotInFilter { <# .SYNOPSIS Retrieves a list of IP printers installed on the device that are not present in the filtered list from Azure tables. .DESCRIPTION The Get-specIPPrintersNotInFilter function compares the names of installed IP printers on the device with a filtered list obtained from Azure tables. It returns the printers that are installed but not in the provided filter, which may require deletion. This is a helper function and may not find many use-cases outside of the specific script it was written for. .PARAMETER azPrinterFilterContent Specifies an array of printer names retrieved from Azure tables. The function compares this list against installed IP printers on the local device to determine which printers are not part of the filter. .EXAMPLES # Example 1: Retrieve IP printers not in the Azure filter $filter = @('Printer1', 'Printer2') Get-specIPPrintersNotInFilter -azPrinterFilterContent $filter .RETURNS Returns an array of installed IP printers that are not found in the provided Azure printer filter. .NOTES Author: owen.heaume Version: 1.0 - Initial release #> [CmdletBinding()] param ( [string[]]$azPrinterFilterContent ) Write-Host 'Getting a list of printer names that are installed on the device, but are not in the filtered list from Azure tables' -ForegroundColor Cyan [int]$count = 0 $printersToDelete = @() #$installedPrinters = Get-Printer # Ensure we only get a list of printers to delete that are IP printers $installedprinters = Get-specInstalledIPPrinters foreach ($instPrinter in $installedPrinters) { # Check if the installed printer's name is NOT in the $azPrinterFilterContent list if ($azPrinterFilterContent -notcontains $instPrinter.Name) { $printersToDelete += $instPrinter $count++ } } Write-Host "Found $count printers that require deletion" -ForegroundColor DarkGray return $printersToDelete } |