Categories:
  🠪  General

Email
  🠪  Servers
  🠪  Testing
  🠪  Tips

Hardware
  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  Tablets
  🠪  Testing
  🠪  Virtualization

hidden
  🠪  General

Links
  🠪  Interesting
  🠪  Media

Network
  🠪  Data
  🠪  Testing
  🠪  VPN

Scripts
  🠪  Batch
  🠪  Linux
  🠪  Powershell

Servers
  🠪  Databases
  🠪  Misc
  🠪  Website

Software
  🠪  Other

Utilities
  🠪  Backup
  🠪  Fix Issues
  🠪  Recovery

Video
  🠪  Editing

Websites
  🠪  HTML
  🠪  Testing

Windows
  🠪  Adjustments
  🠪  Issues
  🠪  Remote Desktop
  🠪  Security
  🠪  Slow
  🠪  Software
  🠪  Startup

Submit Entry
Airin's Notes

Category: Scripts 🠪 Powershell
Swap default printers using Powershell Script
November 30, 2023

$Printers = Get-CimInstance -Class Win32_Printer
$DefaultPrinter = ""
$Printer1 = "RICOH MP C6004"
$Printer2 = "HP LaserJet 600"

foreach ( $Printer in $Printers ){
if ( $Printer.Default ){ $DefaultPrinter = $Printer.Name }
}
write-Host "Old Default printer: $($DefaultPrinter)"

if ( $DefaultPrinter -match $Printer1 ){
$NewPrinter = $Printer2
}else{
$NewPrinter = $Printer1
}
foreach ( $Printer in $Printers ){
if ( $Printer.Name -match $NewPrinter ){
Invoke-CimMethod -InputObject $Printer -MethodName SetDefaultPrinter | Out-Null
}
}

# Check for new printer
$Printers = Get-CimInstance -Class Win32_Printer
foreach ( $Printer in $Printers ){
if ( $Printer.Default ){ $DefaultPrinter = $Printer.Name }
}
write-Host "New Default printer: $($DefaultPrinter)"





This site is meant to be used as a reference for myself, although others may find it useful. I use it to keep track of certain fixes, software, and other solutions which I may need while assisting customers. The page layout is pure HTML/CSS and is kept simple to optimize loading time and fast results.

Return to Airin's Computers