Skip to main content

We are trying to push an HP OfficeJetPro 8020 series to all AAD workstations. 

We followed the worklet but NO GO. HP has 2 drivers, 1) Easy & 2) Full. We tried both but still NO GO.

The policy we created was executed but no action. What’s the magic to achieve that? TIA

Was able to accomplish it with code. Not super clean and perhaps there is a better way. Modify lines 2-7. This will also install printer for ALL users instead of within the user’s profile. This code was modified from a production environment for sharing and has not been tested. Please test.

Most importantly, test using 32-bit powershell running as SYSTEM. Here is the command I use to build my scripts for Automox using a SysInternals tool called psexec. Very handy.
psexec -s -i -d C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell_ise.exe

 

#Office-Printer
$printerIP = '192.168.1.10'
$PrinterName = "Office-Printer"
$PrinterPort = "http://$printerIP`:631"
$driverarchive = 'driver.zip' #zipped contents of driver (avoid multiple INF files or modify line 44 below)
$InfDriverName = 'SHARP UD3 PCL6' # look in the INF file for this, found in model attribute
$DriverName = 'SHARP UD3 PCL6' # How it shows up when using Get-PrinterDriver (install manually to see it)

# Lookup Existing Printers Installed by User
$Printers = Get-ChildItem Registry::\HKEY_Users |
Where-Object { $_.PSChildName -NotMatch ".DEFAULT|S-1-5-18|S-1-5-19|S-1-5-20|_Classes" } |
Select-Object -ExpandProperty PSChildName |
ForEach-Object { Get-Item Registry::\HKEY_Users\$_\Printers\ConvertUserDevModesCount -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Property } | Sort-Object | select -Unique

#region IF Printer that you are looking for is already installed
foreach ($printer in $printers){
IF($printer -match "$PrinterName"){$i++; Write-Output "Found $printer. "}
}
IF($i -gt 0){
#Write-Output "Determined Office-Printers already installed. No action taken. "
Write-Output "Determined $PrinterName already installed. "
#exit 0
}
#endregion

# Test if connectivty to the printer exists, if so go for it
$printserver = Test-NetConnection -ComputerName $printerIP -Port 631
IF($printserver.TcpTestSucceeded -eq $true){

#Add Driver
$driver = try{ Get-PrinterDriver -Name $DriverName -erroraction silentlycontinue } catch { Remove-Variable $driver }
IF(!$driver){
Write-Output "Installing $DriverName. "

# Copy zip file containing driver to windows
Copy-Item ".\$driverarchive" C:\windows\temp\

# Load driver into Windows Driver Store then add it as a driver
$scriptblock = {
# Extract ZIP
Expand-Archive "C:\windows\temp\$driverarchive" -DestinationPath C:\windows\temp\
# Find INF file
$path = $driverarchive.split('.').0]
$inf = (Get-ChildItem "C:\windows\temp\$path\*.inf" -Recurse)s0]
IF($inf){
# Install Driver into windows driver store
## https://docs.microsoft.com/en-us/windows-hardware/drivers/install/driver-store
C:\windows\system32\PNPUtil.exe /add-driver "$inf" /install
}else{write-output "Unable to locate driver INF file. "; exit 0}

# cleanup zip file
remove-item "C:\windows\temp\$path\" -Recurse | out-null
remove-item "C:\windows\temp\$driverarchive" | out-null

#########################################################################################################
# Add Printer Driver by finding it in the driver store
### NOTE YOU WILL NEED TO FIGURE OUT THE NAME OF THE DRIVER by ANALYZING the INF FILE
$inffile = $inf.split('\')\-1]
$windrivers = Get-WindowsDriver -All -Online | Where-Object originalfilename -match $inffile
IF(!$windrivers){write-output "Unable to locate $($inf.Name) driver in Windows Driver Store. ";exit 0}
# -Name in next command was found within the INF file above
Add-PrinterDriver -Name "$InfDriverName" -InfPath $windrivers.OriginalFileName
#########################################################################################################
}
$64bit = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock

$driver = try{ Get-PrinterDriver -Name $DriverName -erroraction silentlycontinue } catch { }
IF(!$driver){Write-Output "Failed to install driver. "}
}

#Add Office-Printer
$printer = try { Get-Printer -Name $PrinterName -erroraction silentlycontinue } catch { Remove-Variable $printer }
IF(!$printer){
Write-Output "Adding Printer $PrinterName. "
Add-Printer -Name $PrinterName -PortName $PrinterPort -DriverName $DriverName
$printer = try { Get-Printer -Name $PrinterName -erroraction silentlycontinue } catch { Remove-Variable $printer }
IF(!$printer){Write-Output "Failed to setup printer $PrinterName. "}
}else{Write-Output "Found $PrinterName already installed. "}

}else{Write-Output "Unable to communicate with $PrinterPort"; exit 0}

 


Reply