Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 17778

Install Printer Drivers with PowerShell in Windows 8

$
0
0

Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell in Windows 8 to install printer drivers.

Microsoft Scripting Guy, Ed Wilson, is here. This morning, it is rainy and overcast here in Charlotte, North Carolina, but it is pleasantly cool. The Scripting Wife migrated to the lanai and is sitting on her swing and checking Facebook on her Windows RT Surface. I am in my office checking email sent to scripter@microsoft.com. I am sipping a cup of English Breakfast tea with a cinnamon stick, lemon grass, hibiscus blossom, orange peel, and a bit of spearmint. It is a very refreshing cup of tea.

When it comes to using Windows PowerShell to install print drivers, there is the long way and the short way. The long way is…well…long and rather complicated. The short way is easy. The difference in the two methods is not necessarily a conscious choice, but rather a function of the drivers already installed in Windows and the print device you intend to hook up.

For example, we all know that Windows ships with a whole bunch of printer drivers already on the disk. They reside in the Windows\inf folder, and they all begin with the letters prn. The following script lists the printer drivers that ship with Windows.

Get-ChildItem ((Get-Item Env:\systemroot).value+"\inf") -Exclude *.pnf -recurse |

Where-Object { $_.name -match "prn" } |

Sort-Object -Property name |

format-table -Property name, length, creationTime, lastWriteTime -AutoSize

Of course, one issue is a bit convoluted. The following image illustrates the output.

Image of command output

The issue is that the names, such as prnbrcl1.inf, do not make too much sense. I can go to the Windows/inf directory, and open the .inf file in Notepad, and I am greeting with something that looks like the following.

Image of file content

If I compare this output with the output from the advanced printer installation dialog box, I can see similarities. This is shown here.

Image of menu

If I select a printer driver from the previous list, and click Next, the driver installs. I can verify this via the Get-PrinterDriver function, as shown here:

Get-PrinterDriver

The following image shows the command and its output.

Image of command output

I can then use the Get-PrinterDriver function to retrieve the newly installed printer:

Get-PrinterDriver -Name "Brother *"

If I attempt to remove it, however, an error message appears, which states that it is being used by a printer. This command and the error message are shown here.

Image of error message

After I remove the printer that uses the driver, I can then remove the printer—but that is tomorrow’s blog post.

To add a printer driver that exists in the driver store, I need to use the actual driver name. I cannot use wildcard characters, or an error message appears. For example to install the "Brother Laser Leg Type1 Class Driver" that I found in the .inf files, I must use the complete name. This command is shown here:

Add-PrinterDriver -Name "Brother Laser Leg Type1 Class Driver"

If I attempt to use Brother *, an error occurs. This message is shown in the following image.

Image of error message

I can also use the Add-PrinterDriver function to install a print driver by specifying the name of the .inf file for that printer driver. One issue is that often printer drivers are “universal drivers,” and the .inf file contains information for dozens of printers. Therefore, Windows PowerShell will not know which driver to install.

That is all there is to using Windows PowerShell to install printer drivers. Printer week will continue tomorrow when I will talk about removing printers.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy


Viewing all articles
Browse latest Browse all 17778

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>