Gathering the Default Printers for Machines in Your Environment

Recently, I was tasked with gathering a list of the default printers for every machine in our environment. However, anyone who has attempted to gather this information remotely understands that gathering the default printer is a difficult task. Typically, the returned value will be empty, causing a panic deep in your core (ok…that was a little too dramatic). Plus, we have to ensure that the user who primarily operates that device is logged in, as the default printer setting is typically defined by the user.

Thank goodness you are brilliant and use SCCM to manage your environment! I’ve always told people that you’re smart…

Essentially, I created two scripts. The first was simply a CMD that ensured the script was launched locally. The second was a Powershell script that queried the default printer of the user and appended the information to a CSV file back on the SCCM server, listing the username and printer. I kept both scripts in the same source directory and created a program for the CMD. Each program was set to run with user’s rights and only when a user is logged on. The deployment was then set to run on next logon.

One catch to the whole thing was that the execution policy on the user machines has to be unrestricted (hence the line written into the first script). The scripts are detailed below. Remember to change the path to the network location in which you want to store the gathered data. Also, ensure that the first line of the PS1 includes and ends after “select name”.

Enjoy!

________________________Printers.CMD________________________

@echo off

cls

Echo Default Printer Query

set cdir=%~dp0.

pushdir %cdir%

powershell.exe -executionpolicy unrestricted -command .\DefaultPrinter.ps1

popd

Exit

________________________DefaultPrinter.ps1________________________

$Printer = Get-WmiObject -namespace root\cimv2 -Query “select * from Win32_Printer Where Default = TRUE” -Impersonation 3 | select name
$env:username+”,”+$Printer.Name | Out-File -append \\<PathToNetworkLocation>\Printers.csv

Advertisements

One thought on “Gathering the Default Printers for Machines in Your Environment

  1. great script for printers but how can I do that without powershell ? because in our environment we have
    an xp machines that even don’t have powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s