SOLVED

deploying printer via intune

Iron Contributor

Hello everyone,

 

I'm in need of assistance with the following script I'm currently using: powershell

 

# Replace the placeholders with your details

$inf_path = ".\driver\KOBxxK__01.inf"

$driver_name = "KONICA MINOLTA Universal V4 PCL"

$driver_path = "C:\Windows\System32\DriverStore\FileRepository\KOBxxK__01.inf"

$printer_name = "Konica 1"

$port_name = “USED MY IP”

$printer_ip_address = “USED MY IP”

 

# Install the driver using Pnputil

pnputil.exe /add-driver "$inf_path"

 

# Add the printer driver using Add-PrinterDriver

Add-PrinterDriver -Name "$driver_name" -InfPath "$driver_path"

 

# Add the printer port using Add-PrinterPort

Add-PrinterPort -Name "$port_name" -PrinterHostAddress "$printer_ip_address"

 

# Add the printer using Add-Printer

Add-Printer -DriverName "$driver_name" -Name "$printer_name" -PortName "$port_name"

 

My objective is to remotely install a Konica printer via Intune using PowerShell. However, I've been unable to get this script to function properly. I placed this script in the folder located before the "Driver" folder.

 

The error 

 

 

errorrrrrr.PNG

 

Could someone please assist me with this issue?

 

 

 

 

18 Replies

Hi @Harm_Veenstra 

 

This worked if I run the script locally but via intune I get this error: 

 

Screenshot 2023-10-13 at 14.06.24.png

 

Any ideas?


Aran

I suggest adding Start-Transcript c:\windows\temp\log.txt at the top of the script and Stop-Transcript at the end. After deployment, check the logs to see what's going on. Are you running it as System?
Yes running as system, I am going to do this and will check and let you know! thanks


1. I would make sure (if you are going to package this in a win32app) that you are using sysnative..
2. add /install after the /add-driver (as shown below)
3. you don't need to specify the inf path if you already installed it.

https://call4cloud.nl/2021/07/what-about-printer-drivers/

###################
#Staging Drivers #
###################
C:\Windows\SysNative\pnputil.exe /add-driver "$psscriptroot\Drivers\eSf6u.inf" /install

#######################
#Installing Drivers #
#######################

Add-PrinterDriver -Name $drivername
Hi,

It doesnt seem to even get that far to create the logs..

The only difference I can see is in the install.cmd I use the command is all lowercase and the file includes uppercase letters would that make a difference?

So command within install.cmd is powershell.exe -executionpolicy bypass -file .\add_printers.ps1 the ps1 is put uppercase Add_Printers.ps1
It's not case-sensitive. That shouldn't make any difference. Could you post a screenshot of your files in a folder, the installation command in Intune, and the contents of the install.cmd? (It's not install.cmd.txt I hope, I helped somebody else who had that as the filename because he didn't have show extensions enabled in the Windows Explorer)

The file is a .CMD @Harm_Veenstra 

 

Here are the screenshots

 

Screenshot 2023-10-16 at 13.37.48.pngScreenshot 2023-10-16 at 13.37.30.pngScreenshot 2023-10-16 at 13.19.37.png

best response confirmed by ABill1 (Iron Contributor)
Solution
Seems ok if you copy all the files in a folder on a test machine (Or Windows Sandbox) and run install.cmd as Administrator... Does that work?
So I tried to run it as admin on local which failed and seems like the install.cmd was currupt some how so I recreated it and locally it worked so I will try packaging it again and trying again.

I will let you know.
Thank you!
If you are going to package it... that app is a win32app... win32 🙂 ..
So you need to make sure you are using the sysnative path to pnputil.

###################
#Staging Drivers #
###################
C:\Windows\SysNative\pnputil.exe /add-driver "$psscriptroot\Drivers\eSf6u.inf" /install
I've got the same issue... The pnputil.exe command works fine when running manually through powershell but failed when deploy through Intune packaged as Win32.
In my environment where my Windows 10 devices do not have C:\Windows\SysNative\pnputil.exe. The folder SysNative doesn't exist at all.
You can find more info about sysnative here: https://call4cloud.nl/2021/05/the-sysnative-witch-project/

and how you can test it from your own device, as looking at that folder with your regular powershell session isn't going to work... as that powershell session is.... how many bits?
Thanks, will take a look at SysNative info.
The PS script containing C:\Windows\SysNative\pnputil.exe /add-driver "$psscriptroot\Drivers\eSf6u.inf" /install
works when running it manually but not through Intune. I guess when Win32 calls pnputil.exe it redirects to SysWOW64 where it does not exist.
Is there another way to add the printer driver into the Windows Driver store without using pnputil.exe?
I use it in my script (See my blog post link above) like this where I try all the pnputil paths 😉

#Add all printer drivers by scanning for the .inf files and installing them using pnputil.exe
$infs = Get-ChildItem -Path . -Filter "*.inf" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Fullname
$totalnumberofinfs = $infs.Count
$currentnumber = 1
Write-Host ("[Install printer driver(s)]`n") -ForegroundColor Green
Foreach ($inf in $infs) {
Write-Host ("[{0}/{1}] Adding inf file {2}" -f $currentnumber, $totalnumberofinfs, $inf) -ForegroundColor Green
try {
c:\windows\sysnative\Pnputil.exe /a $inf | Out-Null
}
catch {
try {
c:\windows\system32\Pnputil.exe /a $inf | Out-Null
}
catch {
C:\Windows\SysWOW64\pnputil.exe /a $inf | Out-Null
}
}
$currentnumber++
}

@Harm_Veenstra am I the only one who noticed that port which you are using is already in use 😂😂?

... yes 😄
1 best response

Accepted Solutions
best response confirmed by ABill1 (Iron Contributor)
Solution
Seems ok if you copy all the files in a folder on a test machine (Or Windows Sandbox) and run install.cmd as Administrator... Does that work?

View solution in original post