Mikkel Damgaard

Skip to main content
< All Topics
Print

Script – Intune Deploy Printers Powershell Script

This article provides an overview of a script developed by Ben Whitmore (https://github.com/byteben), which I have slightly modified to enhance features and logging capability.

The script is designed to deploy local printers to Windows clients via Intune. It works by packaging both the installation and uninstallation PowerShell scripts, along with the necessary printer driver files. The installation script supports multiple custom parameters, making printer deployment streamlined, straightforward and efficient. Additionally, the script includes robust built-in logging, which is stored in the Intune Management Extension logs. This allows IT administrators to access deployment logs directly through Intune without requiring access to the individual client machines.

Install-Printer.ps1

Explanation

This PowerShell script automates the installation of a local printer on a Windows PC using the provided driver files. It accepts custom parameters at runtime, which are used to configure and deploy the printer according to the specified settings. This approach ensures a flexible, consistent, and highly efficient printer installation process across multiple devices.

The script can be integrated with deployment tools such as Intune. By packaging the installation and uninstallation scripts along with the driver files, administrators can deploy and configure printers using the specified parameters. For detailed instructions on configuration and usage, please refer to the usage documentation.

Usage

To install a printer using this script, run it in PowerShell and provide the necessary parameters, which will be used to configure the printer.

The example below demonstrates a full installation command, including all required and optional parameters.

Before deployment, ensure that the correct driver files are present in the root directory of the script. The required files include .inf, .cat, and .cab files. If you are unsure, you can simply unpack the entire driver package into the script’s root folder.

For Intune deployments, package the entire root directory and specify install-printer.ps1 as the installation file. Then, upload the package as a Win32 app in Intune and use the installation commands below to configure the printer according to your environment.

powershell.exe -executionpolicy bypass -file .\Install-Printer.ps1 -PortName "IP_10.10.1.1" -PrinterIP "10.1.1.1" -PrinterName "Canon Printer Upstairs" -DriverName "Canon Generic Plus UFR II" -INFFile "CNLB0MA64.inf"

Below is all optional parameters which can be added to the install command from above. All availiable paper sizes can be found here: Paper Sizes

-color “true / false / 1 / 0 / yes / no”
-PaperSize “A4 / A3 / A5 / Letter / Legal / Executive”
-PrintDuplex “OneSided / TwoSidedLongEdge / TwoSidedShortEdge”

Script Source

Below is the full script source code, with the option to download it. Its also availiable at this Github repository of mine


                    

Remove-Printer.ps1

Explanation

This script can be used to remove a local printer from a Windows PC. It is typically deployed as the uninstall command for the install-printer.ps1 script, but it can also be run as a standalone tool. The script removes the printer based on the local printer name specified in the parameters.

Usage

If deployed on its own, only this script is required. Otherwise, it should be packaged together with the installation script and the printer driver files. When deploying with Intune alongside install-printer.ps1, this script should be used as the uninstall command.

The example below demonstrates how the uninstall command could be executed. In this example, the printer named “Canon Printer Upstairs” will be removed

powershell.exe -executionpolicy bypass -file .\Remove-Printer.ps1 -PrinterName "Canon Printer Upstairs"

Script Source

Below is the full script source code, with the option to download it. Its also availiable at this Github repository of mine


                    

How to Deploy as a Win32 App in Intune

By now you should be able to understand how the scripts works and this makes it a lot easier when it comes to deploying it as a full printer installation via intune. 

Download and extract printer driver

I won’t go into details about downloading and extracting neccesary files as the method may very from vendor to vendor. Go ahead and download the specifc driver for your organizations printer and extract all driver content. The requierd files are .inf, .cab, .cat, once extracted go ahead an place these in the root of your source directory for this win32 app. if not sure what files are neccesery just place all extracted files in root, this is not reccommend but really its just becouse of the size of the intune package which is typicly no big deal just unnecesery. 

Add the scripts to the root directory of the win32 app source

If not already done create a new folder on your pc where both the printer driver files from earlier will be places asswell as the 2 scripts, install-printer.ps1 and remove-printer.ps1. 

The directory should now look something like this: 

my-printer-win32-app\
        Install-Printer.ps1
        oemsetup.inf
        Remove-Printer.ps1
        ricu15.cat

Credits

IMPORTANT: This script is not my own, ive made small adjustments to it, fx logging location, adding support for PaperSize, Color, and Print Duplex. I wanna give all the credits for this very cool script to:

Original Script Author:
Ben Whitmore (https://github.com/byteben)
Source Scripts: 
https://github.com/MSEndpointMgr/Intune/blob/master/Windows%2010/Install-Printer.ps1
https://github.com/MSEndpointMgr/Intune/blob/master/Windows%2010/Remove-Printer.ps1

Tags:
Table of Contents

Leave a Reply

Your email address will not be published. Required fields are marked *