Here’s a worklet that we use to install printers via Automox:
Eval Code:
$testFile = "$env:windir\InstalledPrinters.txt"
$testFileValue = (Test-Path $testFile)
if ($testFileValue -eq $true ) {
Exit 0
} else { Exit 1 }
Remediation Code:
$testServer = "printserver"
$testServerValue = (Test-connection -Computername $testServer -BufferSize 16 -Count 1 -Quiet)
if ($testServerValue -eq $false ) {
Exit 0
Write-Host "printserver not reachable!"
}
else {
Add-Printer -ConnectionName "\\printserver\east-gray"
Add-Printer -ConnectionName "\\printserver\west-color"
New-Item -ItemType file "$env:windir\InstalledPrinters.txt"
}