This set of PowerShell scripts will install a USB or network printer using the provided parameters. It also creates the port and adds the driver to the DriverStore.
PARAMETERS
CertName
This is the name of the certificate file you have added to the same directory as this script runs from including the extension.
This is not a mandatory parameter so if left blank, the script will not run the cert installtion section.
PrinterName
Display name of the printer queue to be created. Example "Office Printer". This exact name also needs to be added into the Printer-Detection.ps1 script.
DriverName
Printer driver name as it appears in Print Management. This needs to be exact. Example "Lexmark Universal v4 XL". This can be obtained from the .inf file for the driver.
PrinterIP
If you are installing a network printer you can add the -PrinterIP parameter to provide the IP address. This is not a mandatory parameter so if this is not used
the script will default to installing the printer as USB.
EXAMPLE
.\Printer-Install.ps1 -CertName "mycert.crt" -PrinterName "Office MFP 3rd Floor" -DriverName "Xerox Global Print Driver PCL6"
EXAMPLE
.\Printer-Install.ps1 -CertName "mycert.crt" -PrinterName "Office MFP 3rd Floor" -DriverName "Xerox Global Print Driver PCL6" -PrinterIP "10.10.10.10"
EXAMPLE
powershell.exe -ExecutionPolicy Bypass -File .\Printer-Install.ps1 -CertName "mycert.crt" -PrinterName "Office MFP 3rd Floor" -DriverName "Xerox Global Print Driver PCL6"
EXAMPLE
powershell.exe -ExecutionPolicy Bypass -File .\Printer-Install.ps1 -CertName "mycert.crt" -PrinterName "Office MFP 3rd Floor" -DriverName "Xerox Global Print Driver PCL6" -PrinterIP "10.10.10.10"
RETURNS
Exit code 0 on success, 1 on failure.
InTune Detection
A detection script is provided but you can also target the registry using the below key updated with the PrinterName.
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\PrinterName"
-- Name must be exactly as it is in the install script --
All driver files need to be added in to a folder called Driver in the script root directory.
Folder Structure
- Printer Name Directory
- Printer-Install.ps1
- Printer-Uninstall.ps1
- Printer-Detection.ps1
- Driver (directory)
- All driver files
InTune Configuration
Install Behavior: System
Detection Rule: Upload the script above (or use the Registry path).
64-bit PowerShell: Ensure "Run script in 64-bit PowerShell" is set to Yes in the detection settings to avoid redirection issues.