I will translate my question in english so that everyone can read it!
Am not really good in powershell i work on it for 3 days.
I need to create a powershell script to show what is the default printer selected in the computer ( example : PrinterA ) before the execute a line to select another printer as default printer ( PrinterB ) .
After that i need to reset the old default printer ( PrinterA ).
I execute line:
Get-WmiObject -query " SELECT * FROM Win32_Printer WHERE Default=$true"
to show default printer but i dont know how to memorize it.
To select the ( printeB ), I do:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "PrinteB"
Can you help me please ?
I'd use
$OldDefaultPrinter = (Get-WmiObject win32_printer | Where-Object Default -eq $True).Name
To store the current default printer in a variable.
To restore with your method
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "$OldDefaultPrinter"
you did not mention the specific version of Powershell that you are using. [ grin ] presuming you are running ps5.1 on win10, you can use the print management cmdlets to do what you need. take a look at this ...
PrintManagement
— https://docs.microsoft.com/en-us/powershell/module/printmanagement/?view=win10-ps
the Get-Printer
cmdlet will get info about the available printers. the Set-Printer
cmdlet will let you set the default printer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.