Link to home
Start Free TrialLog in
Avatar of ssd-tech
ssd-tech

asked on

Script to enumerate all network printers installed - all users

Hello,

I need a script that runs on Win XP all the way to Windows 7 that can be run on machines which will output all user printers. Duplicates are fine. This script would be deployed with Altiris Deployment. I have tried running the powershell command:

get-WmiObject -class Win32_printer | ft name, systemName, shareName

Open in new window


However, this just returns all printers local to the user who ran it, not all of the users on the machine. For example:

User 1 has printers A, B, C installed
User 2 has printers C, D, E installed

We run the script on the above machine, it would output something like
A,B,C,C,D,E are installed on that computer. I have looked around the internet for a while and cannot seem to find anything that outputs every printer on the computer. Thank you

ssd-tech
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Do you need to deploy it from Altiris? Why not just run a script from your computer that has all of the computer names and then query remotely to each PC in the server list?

Something like below...
To get your initial server list simply do the following command

Get-ADComputer -Filter * -Properties * | select Name | Export-csv "c:\ServerExport.csv"

Note: for the script below make sure that the Column Heading in the ServerExport.csv file is computername.

$ServerList = Import-Csv "c:\yourcsvfilehere.csv"
$Serverlist = foreach ($server in $ServerList) {
$server.computername
Get-WmiObject -Class win32_printer -ComputerName $ServerList.computername |
Select-Object Name, ShareName, SystemName |
Export-Csv "c:\PrinterResults.csv"

Open in new window


This will export all of the printers into another CSV file with the headings Name, ShareName, and SystemName.

Hope this helps!
Avatar of ssd-tech
ssd-tech

ASKER

Thank you for this, however this just outputs what printers are local to the machine, and not network printers that are attached. Do you have a modification that can list all printers, including networked ones that exist on network servers for all users? Thank you
ASKER CERTIFIED SOLUTION
Avatar of ssd-tech
ssd-tech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did this script to make it work
This is exactly what I want to do for around 150 user profiles on an old terminal server, but I don't understand how this could work unless all of the users are logged in at the time you run the script.
When I go searching through HKEY_USERS at night, the only entries there are for the users who couldn't be bothered to log off before they ran for the exit door.
I tried to use this script on print server 2008 and i am getting errors. Would be willing to tell me what is wrong?

PS C:\temp> .\getprinter.ps1
Exception calling "OpenSubKey" with "1" argument(s): "Requested registry access is not allowed."
At C:\temp\getprinter.ps1:8 char:5
+     $regProfileList = $regHKLM.OpenSubKey("SOFTWARE\Microsoft\Windows NT\Current ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SecurityException

You cannot call a method on a null-valued expression.
At C:\temp\getprinter.ps1:10 char:22
+     foreach ($sid in $regProfileList.GetSubKeyNames()) {
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

CloseAllRegs : The term 'CloseAllRegs' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\temp\getprinter.ps1:24 char:5
+     CloseAllRegs
+     ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (CloseAllRegs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At C:\temp\getprinter.ps1:7 char:5
+     $regHKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IOException

Exception calling "OpenSubKey" with "1" argument(s): "Requested registry access is not allowed."
At C:\temp\getprinter.ps1:8 char:5
+     $regProfileList = $regHKLM.OpenSubKey("SOFTWARE\Microsoft\Windows NT\Current ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SecurityException

You cannot call a method on a null-valued expression.
At C:\temp\getprinter.ps1:10 char:22
+     foreach ($sid in $regProfileList.GetSubKeyNames()) {
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

CloseAllRegs : The term 'CloseAllRegs' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\temp\getprinter.ps1:24 char:5
+     CloseAllRegs
+     ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (CloseAllRegs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\temp>