In some cases, it would be nice that the default printer can be set to different printer automatically based on where and/or when you log into a computer in a network. And fortunately, you can do so with the help of a couple of PowerShell commands.
Cmdlet to use
We will be using Get-WmiObject cmdlet along with the Win32_Printer class to get the list of printers installed on the computer to start with. The standard use of Get-WmiObject as follows:
Get-WmiObject -Class W32_Printer
As we can see, simply running this cmdlet won’t helps us fulfill the mission. We will need to pick the printer we want to set to default, and pass it to a variable. Through that variable that has all the information about the printer, we can accomplish the mission through a simple SetDefaultPrinter() method.
## get the printer $printer = Get-WmiObject -Query "Select * From Win32_Printer Where Name = 'name of the printer'" ## set the printer as default $printer.SetDefaultPrinter()
Note that if you are defaulting a network mapped printer, use ShareName instead of Name in the command listed above. The following screenshot shows off how the command runs on the PowerShell console to set up a network mapped printer named “Corp-6” as default printer.
Embeding the code into the login script
If you are using the batch file as your login script, you can then simply put the following codes into your batch file.
REM get the printer PowerShell -Command {$printer = Get-WmiObject -Query "Select * From Win32_Printer Where Name = 'name of the printer'"} REM set the printer as default PowerShell -Command {$printer.SetDefaultPrinter()}
That’s about it. Hope it helps.