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”.
Echo Default Printer Query
powershell.exe -executionpolicy unrestricted -command .\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