I have to install some printers via SCCM. I am removing all previously installed printers with the Remove-Printer command and then installing the a group of printers we want installed. I will have multiple scripts based on Office locations, etc. We run a script as Admin to add the reg key to allow printers installs without a prompt first, followed by this script to install as the user, and ending with a script to remove the reg key added in the first script. It has been working fairly well as a SCCM Package, but I would like to run it as an Application and that will require a Detection Method.
I would like to use PowerShell as the Detection method. What I came up with was the following:
$Installed = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\Client Side Rendering Print Provider\S-1-5-21-*\Printers\Connections\*" | Select-Object -ExpandProperty PSChildName)
This results in the network printers installed on my laptop. I need to detect that the printers I want installed are in this variable. If any additional printers are there, it does not matter - I just need to confirm that the printers I deploy are in the list.
All I can come up with is the following:
$Test = ($Installed -ccontains ",,SERVER01.domain.com,SPR-LaserJet" -and $Installed -ccontains ",,SERVER02.domain.com,CHI-CP-MAIN")
If ($Test -eq $true)
{
Write-Output "Success!!"
}
else {}
While this will work, I was wondering if there was a better way to do this? I will have multiple scripts and some will require several printers.
Thanks in advance.