Copy to Clipboard
$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)"
|