How to set default printer using PowerShell
Introduction
This PowerShell script shows how to set default printer in Windows.
Scenarios
In real world, we usually have multiple printers in our company environment. IT admins want to user regularly use specified printer, they have to let user to pick one as default printer.
Script
Step1: Execute this script is simple, if you do not know how to execute it. You can type the command Get-Help C:\Script\SetDefaultPrinter.ps1 -Full to display the entire Help file for this function, such as the syntax, parameters, or examples.
Step2: Start the PowerShell Console with administrator. To run the script in the Windows PowerShell Console, type the one command< Script Path> with parameter at the Windows PowerShell Console.
For example, type C:\Script\SetDefaultPrinter.ps1 -PrinterName "Microsoft XPS Document Writer"
The step is shown in the following figure.

Here are some code snippets for your references.
Try
{
Write-Verbose "Get the specified printer info."
$Printer = $Printers | Where{$_.Name -eq "$PrinterName"}
If($Printer)
{
Write-Verbose "Setting the default printer."
$Printer.SetDefaultPrinter() | Out-Null
Write-Host "Successfully set the default printer."
}
Else
{
Write-Warning "Cannot find the specified printer."
}
}
Catch
{
$ErrorMsg = $_.Exception.Message
Write-Host $ErrorMsg -BackgroundColor Red
}
Try { Write-Verbose "Get the specified printer info." $Printer = $Printers | Where{$_.Name -eq "$PrinterName"} If($Printer) { Write-Verbose "Setting the default printer." $Printer.SetDefaultPrinter() | Out-Null Write-Host "Successfully set the default printer." } Else { Write-Warning "Cannot find the specified printer." } } Catch { $ErrorMsg = $_.Exception.Message Write-Host $ErrorMsg -BackgroundColor Red }
Prerequisite
Windows PowerShell 2.0
Windows 7