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:
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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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("SOFTW ARE\Micros oft\Window s 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.GetSubKeyN ames()) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
+ 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.RegistryK ey]::OpenR emoteBaseK ey("LocalM achine", ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~
+ 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("SOFTW ARE\Micros oft\Window s 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.GetSubKeyN ames()) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
+ 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>
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("SOFTW
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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.GetSubKeyN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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.RegistryK
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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("SOFTW
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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.GetSubKeyN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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>
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.
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!