Set the Default Printer Using PowerShell in Windows

Recently, I was helping an organization automate their workstation setup process, and one of the requirements was to set the default printer via script. If you manage multiple computers or frequently need to switch your default printer, it’s a good idea to use PowerShell.

In this tutorial, I will show you several ways to set the default printer using PowerShell in Windows. These methods work great whether you’re managing a single computer or deploying settings across an enterprise environment.

Method 1 – Using WMI to Set the Default Printer

The Windows Management Instrumentation (WMI) method is perhaps the most straightforward approach to set a default printer using PowerShell. Here’s how to do it:

$printerName = "HP LaserJet Pro M404dn"
(Get-WmiObject -Query "SELECT * FROM Win32_Printer WHERE Name='$printerName'").SetDefaultPrinter()

In this example, I’m setting an HP LaserJet printer as the default. You’ll need to replace “HP LaserJet Pro M404dn” with the exact name of your printer as it appears in Windows.

To verify the change took effect, you can run:

Get-WmiObject -Class Win32_Printer | Where-Object {$_.Default -eq $true} | Select-Object Name

This method works well on Windows 7 through Windows 11, but Microsoft has been gradually moving away from WMI in favor of CIM (Common Information Model).

Check out Set Password for Local User in Windows 11 Using PowerShell

Method 2 – Using CIM to Set the Default Printer

For newer versions of Windows, especially Windows 10 and Windows 11, using CIM is the recommended approach:

$printerName = "Brother MFC-L2750DW"
Invoke-CimMethod -ClassName Win32_Printer -MethodName SetDefaultPrinter -Arguments @{Name=$printerName}

The advantage of using CIM is that it’s more secure and efficient than WMI. To check your current default printer using CIM:

Get-CimInstance -ClassName Win32_Printer | Where-Object {$_.Default -eq $true} | Select-Object Name

I typically use this method when writing scripts for modern enterprise environments since it’s more future-proof.

Check out Set the Time Zone Using PowerShell in Windows

Method 3 – Using .NET Framework

If you’re looking for another approach, particularly one that works well in older versions of PowerShell, you can leverage the .NET Framework:

$printerName = "Xerox WorkCentre 6515"
Add-Type -AssemblyName System.Drawing
$printers = New-Object System.Drawing.Printing.PrinterSettings
$printers.PrinterName = $printerName
$printers.SetDefault()

This method is particularly useful when you need to integrate printer configuration with other .NET-based automation tasks.

Method 4 – Registry Method

For scenarios where you need more control or when other methods fail, you can directly manipulate the registry:

$printerName = "Canon PIXMA TR8620"
$regPath = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows"
Set-ItemProperty -Path $regPath -Name "Device" -Value "$printerName,winspool,Ne00:"

I recommend using this method only as a last resort since direct registry manipulation requires careful testing and can potentially cause issues if done incorrectly.

Read Update PowerShell on Windows 11

Method 5 – Using Group Policy for Enterprise Deployment

If you’re managing a large number of computers in an enterprise environment, you can use PowerShell to create scripts that will be deployed via Group Policy:

# Save this as SetDefaultPrinter.ps1
$printerName = "Ricoh MP C3004ex PCL 6"

# First verify the printer exists
$printerExists = Get-Printer -Name $printerName -ErrorAction SilentlyContinue

if ($printerExists) {
    # Set as default using CIM
    Invoke-CimMethod -ClassName Win32_Printer -MethodName SetDefaultPrinter -Arguments @{Name=$printerName}
    Write-Output "Successfully set $printerName as the default printer."
} else {
    Write-Error "Printer '$printerName' does not exist on this system."
}

This script includes error checking to ensure the printer exists before attempting to set it as the default. It can be deployed via Group Policy by creating a GPO that runs this PowerShell script at user logon.

Read List Windows Features Using PowerShell

Advanced Usage: Getting All Available Printers

Before setting a default printer, you might want to see what printers are available on the system:

# List all available printers
Get-Printer | Select-Object Name, ComputerName, PortName, Shared | Format-Table -AutoSize

This command provides a clear view of all printers, making it easier to identify the exact printer name you need to use.

Handling Network Printers

If you need to set a network printer as the default, first ensure it’s added to the computer:

# Add network printer
Add-Printer -ConnectionName "\\PrintServer\Marketing Printer"

# Set it as default
$printerName = "\\PrintServer\Marketing Printer"
Invoke-CimMethod -ClassName Win32_Printer -MethodName SetDefaultPrinter -Arguments @{Name=$printerName}

This two-step process ensures the network printer is properly installed before setting it as the default.

Check out Check for Windows Updates Using PowerShell

Create a User-Friendly Function to Reuse

To make this process even easier and reusable, I created a reusable function like below:

function Set-DefaultPrinter {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [string]$PrinterName,

        [Parameter(Mandatory=$false)]
        [switch]$AddIfMissing,

        [Parameter(Mandatory=$false)]
        [string]$NetworkPath
    )

    # Check if printer exists
    $printerExists = Get-Printer -Name $PrinterName -ErrorAction SilentlyContinue

    # If printer doesn't exist and AddIfMissing is specified
    if (-not $printerExists -and $AddIfMissing -and $NetworkPath) {
        try {
            Add-Printer -ConnectionName $NetworkPath
            Write-Output "Added network printer: $NetworkPath"
        } catch {
            Write-Error "Failed to add printer: $_"
            return
        }
    } elseif (-not $printerExists) {
        Write-Error "Printer '$PrinterName' does not exist on this system."
        return
    }

    # Set as default
    try {
        Invoke-CimMethod -ClassName Win32_Printer -MethodName SetDefaultPrinter -Arguments @{Name=$PrinterName}
        Write-Output "Successfully set '$PrinterName' as the default printer."
    } catch {
        Write-Error "Failed to set default printer: $_"
    }
}

# Example usage:
# Set-DefaultPrinter -PrinterName "HP LaserJet Pro M404dn"
# Set-DefaultPrinter -PrinterName "Marketing Printer" -AddIfMissing -NetworkPath "\\PrintServer\Marketing Printer"

This function provides a more robust solution with error handling and the ability to add network printers if needed.

Troubleshooting Common Issues

Throughout my years of experience, I’ve encountered several common issues when setting default printers via PowerShell:

  1. Printer name mismatch: Ensure you’re using the exact printer name as it appears in Windows.
  2. Permission issues: Run PowerShell as Administrator if you encounter permission errors.
  3. Network printer connectivity: Make sure network printers are accessible before trying to set them as default.
  4. User profile specificity: Remember that default printer settings are per-user. If you need to set it for all users, you’ll need to use Group Policy or run the script for each user profile.

If you encounter errors, this command can provide detailed information about your printer configuration:

Get-Printer | Format-List *

In this tutorial, I have explained how to set the default printer using PowerShell in Windows. We saw different methods. You can use the same techniques for managing a single computer or hundreds across an enterprise.

If you have any questions or suggestions, feel free to share them in the comments below!

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.