Is there a way to find out what printer a user has mapped on windows print server

Hi

I am trying to fix script that can collect the mapped network printer information from the users's laptops or Windows 2008 R2  print server.

The script should create log files with username, hostname, ip address of the laptop, printer names, server name where the user is mapped. We are not using GPO for printers

I found a script online that is possible to generate that information but when I ran all logs files are empty.
Here is a link http://powershell.com/cs/media/p/16643.aspx 

Please assist,

Thank you, Michal
GetMappedNetworkPrinters.ps1.txt
michalek19Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Easiest way to do it would be to create a login script (or add this to the login script) for each of your users:

reg query "hkcu\software\microsoft\windows nt\currentversion\printerports" > \\someshare\%username%.txt

Ensure to have a share where the file will be created or somewhere on the C: drive and this will give you the dump from the registry for all printers installed for the logged on user.  Each file will be saved as the logged on username.
0
michalek19Author Commented:
do you have login script sample?
0
michalek19Author Commented:
I found other script on Expert Exchange that can help me to achieve but i am getting errors when i ran

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28183483.html

errors out:

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
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
The reason you are having errors is that there is a service on each computer called "Remote Registry" which is not running.  It is not recommended to have the service start automatically as it can be a security risk and that is why I am suggesting you create a GPO.  If you wish, you could go ahead and start the service on each PC and then run your script.

Refer to link below on how to create a user logon script and add below to the script file.  Ensure to change it to point a real share:

https://www.petri.com/setting-up-logon-script-through-gpo-windows-server-2008
https://technet.microsoft.com/en-us/magazine/dd630947.aspx

reg query "hkcu\software\microsoft\windows nt\currentversion\printerports" > \\someshare\%username%.txt
0
michalek19Author Commented:
Thx for providing this method.
However, I would like to run powershell script against win7 computers and pull mapped printer list for each computer.

Do you think the getmappednetworkprinters,ps1 script can be executed against list of computers?
Do you know what i need to change in that script?
0
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Remote Registry service needs to be running on the computers if you wish to read data from the registry.  What is wrong with a GPO running at user login?

If you really want to do it remotely then why don't you create a Computer Logon GPO which starts the remote registry service on the computers during bootup when on the network.
0
michalek19Author Commented:
There is nothing wrong with GPO and I will use this method.
However, even thought you provide URL link, do you have a great sample of the logon script?
0
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
The logon script will be a .cmd file (i.e. user-printers.cmd) and there will be only one line in the script:

reg query "hkcu\software\microsoft\windows nt\currentversion\printerports" > \\someserver\someshare\%username%.txt

Once the logon is in place for at least 1.5 hours, get your users to reboot their PC.  In the share "\\someserver\someshare\" there will text files each corresponding to a username.

From here on, you could validate which user has which printers, etc.
0
michalek19Author Commented:
You know what, i can't use GPO policy. My company doesn't allow to modify existing GPO settings.

The other option will be Landesk or script.

Any advice?

Thx
0
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Go and check one of the users profile in Active Directory and see if there is a logon script for the user.  If there is then edit the logon script and add that line I had mentioned.  If there is no logon script then create the file mentioned above in "C:\windows\SYSVOL\domain\scripts" folder.

Go to AD Users and Computers, highlight all your users, right click and click on properties, click on Profile tab, check the box "Logon script" and type in user-printers.cmd

Now when your users logon, you will see file for each user in the share.

Landesk will cost you a pretty penny for nothing, you could implement SpiceWorks, LanSweeper, etc.  Check them out:

http://www.spiceworks.com
http://www.lansweeper
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
michalek19Author Commented:
In AD logon script is great out and i can't edit that file.

We are using Landesk for windows platform so that would be probably way to go.
Do you know landesk?
0
michalek19Author Commented:
I will accept your solution as you provided logical solution
0
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Thank you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.