📄 Overview
This PowerShell script is designed to automate the installation of a network printer through powershell Script, This script can be use in RMM tools, Intune. It handles the entire process, including downloading the required driver package, extracting it, staging the driver using Pnputil, and finally configuring the printer port, driver, and logical printer object using PowerShell cmdlets (Add-PrinterDriver, Add-PrinterPort, Add-Printer). This is part of the Automated Printer Deployment Script Guide.
It is structured for clear configuration and robust error handling at each stage.
This section details the Automated Printer Deployment Script Guide to ensure seamless installation and management of network printers.
Script for local installation : Automated Printer Installation Script Documentation (Run Locally)
⚙️ Configuration Variables
The script relies on several variables for configuration. You must verify and update these values to match your specific printer and network environment.
| Variable | Example Value | Description |
|---|---|---|
$Url1 | https://.../setup.zip | The direct URL to the compressed driver file (must be a .zip file). Upload file to any publicly accessible location, such as an Azure Blob. |
$ZipFile | C:\Windows\Temp\setup.zip | The local path where the driver ZIP file will be temporarily saved. |
$DriverFolder | C:\Windows\Temp\Driver | The sub-folder where the ZIP contents will be extracted. |
$InfFile | $DriverFolder\CNP60MA64.INF | The exact path and name of the primary INF file within the extracted driver package. This is critical for Pnputil. |
$PrinterIP | 192.168.1.20 | The static IP address of the physical network printer. |
$DriverName | "HP Generic PCL6" | The exact name of the printer model or driver as listed inside the INF file. |
$PortName | "IP_192.168.1.20" | The name for the newly created standard TCP/IP port. It’s automatically constructed from the IP address. |
$PrinterName | HR Printer" | The friendly name you want the printer to be listed under in the Windows control panel. |
🛠️ Step-by-Step Breakdown
The script executes in six main stages:
1. Download and Extract Driver
- Uses
Invoke-WebRequestto securely download the driver ZIP file from the specified$Url1to the$ZipFilepath. - Uses
Expand-Archiveto extract the contents of the ZIP into theC:\Windows\Tempdirectory, ensuring the target INF file is available at the$InfFilepath. - Includes a
try/catchblock to handle network or file extraction errors.
2. Add Driver using Pnputil
- The script uses
Pnputil /add-driver $InfFile /installto stage the driver package into the Windows DriverStore and attempt installation.- Pnputil is a built-in Windows utility for managing driver packages.
3. Find the DriverStore Path
- This is a crucial step because
Add-PrinterDriverneeds the final, unique path of the INF file after Windows has staged it. - It uses
Get-ChildItemto search theC:\Windows\System32\DriverStore\FileRepositorydirectory for the specific driver file name (CNP60MA64.INF). - The result is stored in the
$DriverStorePathvariable. If the path isn’t found, the script terminates, as the printer components cannot be added without it.
4. Add Printer Components
- This section uses the built-in PowerShell Printer Management cmdlets:
Add-PrinterDriver: Installs the driver in the print subsystem, referencing the$DriverNameand the confirmed$DriverStorePath.Add-PrinterPort: Creates a new standard TCP/IP port named$PortNamepointing to the printer’s$PrinterIP.Add-Printer: Creates the final logical printer object in Windows, linking the$DriverNameand$PortNameunder the user-friendly$PrinterName.
5. Verification
- The script concludes by running
Get-Printerto display the properties of all installed printers, confirming that the new printer is listed with the correct driver and port names.




