/
/

How to Automate the Creation of Local Printer Mappings via GPO and PowerShell

by Francis Sevilleja, IT Technical Writer
How to Automate the Creation of Local Printer Mappings via GPO and PowerShell blog banner image

Local printer mapping streamlines printer assignments within large, multi-department environments, allowing end-users to print consistently using the correct devices. This helps simplify device assignments when printing, smoothing out workflows while boosting productivity through user-first configurations.

Methods for effective local printer mapping

Manual printer assignments often lead to errors and failed print jobs, increasing support ticket inflow while placing extra strain on technicians. Through IT automation, technicians can provide consistent printer assignments across workplaces and simplify post-imaging and onboarding processes.

📌 Prerequisites:

  • Windows Server 2012 or later
  • Windows 10/11 Pro or Enterprise client devices
  • Shared printers published to Active Directory
  • Script execution turned on
  • IP-addressable local printers
  • Optional: NinjaOne RMM platform

📌 Recommended deployment strategies:

Choose a Method

💻

Best for Individual Users

💻💻💻

Best for Enterprises

Method 1: Map printers using Group Policy Preferences (GPP)
Method 2: Use PowerShell to map shared or local printers
Method 3: Automate local printer mapping through logon/logoff scripts
Method 4: Track printer mapping status in the Registry
Method 5: Deploy targeted scripts based on dynamic criteria

Method 1: Map printers using Group Policy Preferences (GPP)

📌 Use Cases: GPP automatically connects users or computers to nearby printers. Unlike old login scripts, this keeps connections reliable and ensures they don’t break after a reboot. GPP also supports per-user and system-wide printer settings for better control and flexibility.

📌 Prerequisites:

  • Group Policy Management Console (gpmc.msc)
  • Domain administrator privileges.

⚠️ Important: Verify GPPs locally before deploying them across an organizational unit. (See ⚠️ Things to look out for.)

  1. Launch the Group Policy Management Console.
  2. Right-click the target Organizational Unit (OU), then select Create a GPO, and link it here….
  3. Navigate the following path:

User Configuration > Preferences > Control Panel Settings > Printers

  1. Right-click Printers, select New > Shared Printer, and set the parameters.
    • Action: Create
    • Share path: \\<print-server-name>\<printer share name>
    • Optionally, you can check Set this printer as default printer.

💡 Tip: You can find Share Path by launching printmanagement.msc, then going to your target Printer Server. Right-click the target printer, select Properties, and then press the Sharing tab.

  1. On the Common tab, enable Item-Level Targeting (ILT) and add your conditions to apply the preference within specified criteria.
  2. Open PowerShell on the target device and enter the following command: gpupdate /force
  3. Verify the changes by entering the following PowerShell command:
$computername = # Input your computer name
rundll32 printui.dll,PrintUIEntry /ge /c”\\$computername”

Method 2: Use PowerShell to map shared or local printers

📌 Use Cases: Leverage PowerShell scripts to support local TCP/IP or shared printer mapping. Additionally, the scripts in this section can be executed through RMM platforms, providing automated printer assignments for end users.

📌 Prerequisites:

  • Pre-installed printer drivers.
  • Admin rights.

Sample shared printer mapping script:

The script below creates a connection to shared printers via a print server.

$printersharename = \\<print-server-name>\<printer share name>
# (e.g., \\<print-server-name>\<printer share name>)
Add-Printer -ConnectionName “$printersharename”

💡 Note: Replace the placeholders with the actual values for the print server name and printer share name.

Sample local TCP/IP printer mapping script:

This script creates a local printer connection inside an endpoint, sending jobs directly to a printer, bypassing the Print Server.

$portName = “IP_192.168.1.250”
Add-PrinterPort -Name $portName -PrinterHostAddress “192.168.1.250”Add-Printer -Name “Warehouse Zebra Printer” `
            -DriverName “Zebra ZP 500 (ZPL)” `
            -PortName $portName

💡Note: Replace the placeholder values with the actual IP address of the target printer and the correct driver name available in your system.

Command to set a default printer:

$name = #insert printer name (e.g., Warehouse Zerbra Printer)

Set-Printer -Name “$name” -IsDefault $true

⚠️ Important: Verify script syntax accuracy before executing it on a local machine or across multiple endpoints. (See ⚠️ Things to look out for.)

Method 3: Automate local printer mapping through logon/logoff scripts

📌 Use Cases: Use the Task Scheduler or logon/logoff scripts to provide a consistent printer mapping for end users every session. This method also prevents policy drift as it allows the configuration to automatically fix itself on the next trigger.

📌 Prerequisites:

  • Group Policy Management Console (gpmc.msc)
  • Domain administrator privileges.
  • Task Scheduler access.

Sample logon script via elevated CMD prompt:

Create a custom local print mapping script or select one from the sample scripts provided in Method 2. Save your script as a .ps1 file within your preferred path. In this example, the script will be saved at “C:\Scripts\MapPrinters.ps1”.

schtasks /create /tn “MapPrinters” /tr “powershell.exe -File C:\Scripts\MapPrinters.ps1” /sc onlogon /ru SYSTEM

💡 Note: MapPrinters.ps1 doesn’t exist by default and must be created manually by administrators with the required printer mapping logic. After creation, store the script on the Domain Controller for Active Directory access and distribution via logon or logoff scripts.

Configure logon script via GPO:

Alternatively, logon scripts can be configured within the Group Policy Management Console.

  1. Open gpmc.msc and create a GPO linked to your target OU or edit an existing one.
  2. Navigate the following path:

User Configuration > Windows Settings > Scripts (Logon/Logoff)

  1. Add your preferred script as a logon script by browsing and adding the correct .ps1 file.
  2. Configure the Turn on Script Execution policy to allow script execution by going to:

Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell > Turn on Script Execution

Method 4: Track printer mapping status in the Registry

📌 Use Cases: Leverage the Registry to tag devices with printer mapping configurations, allowing GPP item-level targeting (ILT) to skip remapping once the key exists. Additionally, this helps technicians to query endpoints and quickly identify non-compliant devices for remapping.

⚠️ Warning: Misconfigurations in the Registry can lead to system instability and impact device performance. (See ⚠️ Things to look out for.)

Sample PowerShell script to tag devices with successful printer mappings:

New-Item -Path “HKCU:\Software\Org\PrinterMapping” -Force

Set-ItemProperty -Path “HKCU:\Software\Org\PrinterMapping” -Name “LastMapped” -Value (Get-Date).ToString(“u”)

Set-ItemProperty -Path “HKCU:\Software\Org\PrinterMapping” -Name “MappedPrinters” -Value “Accounting-Printer, Warehouse Zebra”

Sample PowerShell query for Registry tags:

if (Test-Path ‘HKCU:\Software\Org\PrinterMapping’) { Get-ItemProperty ‘HKCU:\Software\Org\PrinterMapping’ } else { ‘Missing’ }

Method 5: Deploy targeted scripts based on dynamic criteria

📌 Use Cases: Deploy dynamic scripts to get the IP and group-based endpoint details, automating printer assignment according to user location and department. When leveraged as a logon script, this keeps printer assignments correct, reducing misprints and errors.

⚠️ Warning: Dynamic scripts are powerful but risky, as vague requirements, weak validation, and missing safeguards can cause misconfigurations. (See ⚠️ Things to look out for.)

Sample IP-based targeting script in PowerShell:

$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.PrefixOrigin -eq “Dhcp” }).IPAddress

if ($ip -like “192.168.10.*”) {
        Add-Printer -ConnectionName “\\PrintServer01\Accounting-Printer”
 }
elseif ($ip -like “192.168.20.*”) {
         Add-Printer -ConnectionName “\\PrintServer01\Sales-Printer”
}

💡 Note: Replace the placeholder group name with one that exists in your Active Directory. Additionally, adjust the printer path to the correct printer share in your setup.

Sample group-based targeting script in PowerShell:

$groups = (whoami /groups)

if ($groups -match “Accounting”) {
        Add-Printer -ConnectionName “\\PrintServer01\Accounting-Printer”
}

⚠️ Things to look out for

Risks

Potential Consequences

Reversals

Deploying untested GPPsGPPs can hide misconfigurations that can severely affect local printer mappings.Test configurations within a controlled environment to ensure their effect and validity before broad deployment.
Inaccurate script syntaxInaccurate scripts can cause errors, preventing printer mapping configurations from being applied successfully.Test scripts locally to ensure their validity, then deploy them in phased rollouts to gradually monitor impact and reduce risk.
Registry misconfigurationsWrong changes in the Registry can severely impact device performance and stability.Back up your Windows Registry before making changes to ensure easy rollback in case of misconfigurations.
Poorly-written dynamic scriptsAlthough powerful, dynamic scripts can introduce potential failure points because they rely on multiple factors, which may result in inaccurate printer mappings.Carefully validate scripts, use clear naming conventions during group checks, and watch out for VPNs when using dynamic scripts.

Troubleshooting issues related to local printer mapping

Things can go wrong when adding local printers via GPO and scripts. In this section, we’ll show you fixes for the common issues when mapping local printers.

Issue #1: Printer not appearing when adding local printer via GPO

Open a PowerShell prompt and run the following script: gpresult /h report.html

Open report.html and verify that the applied configurations are correct. Additionally, ensure that the GPO is linked to the correct OU and that the target printer’s share permission is enabled.

Issue #2: Driver install issues

Local printer mapping may fail if a printer’s driver is blocked by policy or if the wrong one is installed. To mitigate this, manually or using the Add-PrinterDriver cmdlet, pre-install printer drivers on the target endpoint.

In addition, you can launch gpmc.msc, then create or edit a linked GPO to the target OU. Navigate to Computer Configuration > Policies > Administrative Templates > Printers, then right-click and edit Point and Print Restrictions by specifying your target printer server names.

Issue #3: Script not executing

Open gpmc.msc, create or edit a GPO, and navigate to Computer Configuration > Windows Components > Windows PowerShell. Configure the Turn on Script Execution policy by selecting Allow local scripts and remote signed.

Technicians can also add simple logging to scripts, such as Out-File C:\Temp\MapPrinters.log -Append, preventing silent failures.

Issue #4: Registry keys missing

Double-check if you’re targeting the correct Registry hive. For per-user printers, run the script in the user’s context by querying the HKCU hive. On the other hand, system-wide mappings should use HKLM instead.

Considerations when managing local printers on endpoints

Local printer mapping streamlines how print jobs are distributed across printers in an environment. It’s a strong tool on its own, but below are considerations to help you get the most out of it.

Avoiding duplicate printers

Multiple instances of the same script can accidentally create duplicate printers, wasting time in the process. Add Get-Printer -Name “PrinterName” to your script, allowing it to check if a printer already exists to avoid duplication.

Offline printer fallback

Unreachable printers can lead to slow logon times and mapping failure. To skip mapping unresponsive printers or servers, add Test-Connection -Quiet -Count 3 “PrinterName” to a PowerShell script.

Printer permissions

Even with a good local print mapping practice, users won’t be able to print without the correct share permissions. Launch printmanagement.msc, navigate to Printer Properties > Security of your target printer, and confirm the right groups have Print rights.

NinjaOne services to automate local printer device management

NinjaOne offers automated services that can help MSPs and internal IT to deploy dynamic printer assignments at scale.

NinjaOne service

Definition

How does it help local print mapping

Remote PowerShellRemote PowerShell enables technicians to run scripts remotely in real-time.Automate the deployment of local print mapping PowerShell scripts consistently and centrally across an environment.
Custom fieldsTechnicians can use custom fields to store information within an endpoint, providing deeper device insights at a glance.Use custom fields to tag, organize, and target specific devices, allowing for more precise and efficient script deployment.
Real-time monitoring and automated alertingAllows proactive monitoring of endpoints and creation of custom alerts for faster MTTR.Monitor local print mapping consistently and use custom alerts to trigger remediation scripts automatically, reducing the need for manual execution.
Policy-based automationStandardizes system configurations across endpoints while automating patches for compliance and maintenance.Leverage this service to trigger actions on printer mapping policy automatically drifts before they break compliance.

Automate local printer mapping for streamlined management and troubleshooting

You can use PowerShell and CMD scripts to automate local printer deployments. Additionally, setting scripts to automatically execute at logon can help enforce consistency for every user across an environment.

For central deployments, you can use GPOs to configure shared printer mappings paired with Registry tags for item-level targeting. Alternatively, use an RMM platform, such as NinjaOne, for better endpoint visibility and automation of printer-related policies.

Related topics:

You might also like

Ready to simplify the hardest parts of IT?