HOWTO: Printer Inventory Script w/ Network Printers

Greetings all,

Introduction: A while back, our team was requested to retrieve through SCCM the printer mappings for all users. A quick search lead us to (social.technet.microsoft.com/Forums/en-US/configmgrgeneral/thread/59fc480a-6edb-41a7-9ffd-239a37e07cac/) which directs you to some scripts hosted by sccmexperts.com to retrieve printer information through WMI and place it in another temporary WMI class for the hardware inventory agent to pick up later. The script appears to be functional, but the problem we had was that non administrators do not have permissions to write to WMI. After inquiring about this in another post (myitforum.com/forums/tm.aspx?m=232593) Sherry Kissinger confirmed the thought that I was going to have to store this information in the registry somewhere.

Again there is the problem with permissions writing to the registry. There is a built in command called Regini that will take information from a .txt file and create a registry structure based on the property information in the .txt file. What I did was use regini to create a registry key in HKEY_LOCAL_MACHINE called SCCMINV and populate the printer inventory information in a sub key called PRINTINV. These keys are given full permissions for the Administrators group, System Account, and all Interactive users. After the registry structure has been set up, a script can then be run under the user’s profile to add the appropriate printer information to the registry. Once the data is populated in the registry, the sccm hardware inventory (after the SMS_DEF.mof file has been updated on the server) can collect the data and populate it in a custom table in the SCCM database.

Steps for Implementation

1) Modify SMS_DEF.mof and Configuration.mof: I have attached the mof additions needed to collect the information taken from the scripts. Credit is given to regkey2mof for making the mof files possible and to Sherry Kissinger for her input towards verifying information about how Dynamic Instances work. The contents of these files need to be appended to the end of the respective configuration.mof and sms_def.mof located at “c:\Program Files (x86)\Microsoft Configuration Manager\inboxes\clifiles.src\hinv” on your primary SCCM server. Make sure you have a backup of both of these files prior to modifying them.

2) Create a package for the printer inventory: I chose to create a package to advertise the Regini and VBS needed to collect the printer inventory. Extract the SCCM_PRINTER_INV.vbs and SCCM_REGINI.txt to a source directory, create a package and distribute to your distribution points.

3) Create a program for the Regini: Create a new program with the following attributes…
Command Line: C:\Windows\System32\regini.exe SCCM_REGINI.txt
Run: Hidden, on any platform.
Environment: Run whether or not a user is logged on (Admin rights)
I suppress program notifications because of the frequency of the program but that is up to you.

4) Create a program for the SCCM_Printer_Inv.vbs: Create a new program with the following attributes…
Command Line: cscript SCCM_PRINTER_INV.vbs
Run: Hidden, on any platform.
Environment: Run only when a user is logged with the user’s rights. This is needed because the WMI classes have to be referenced by the user to get the user’s information. If it is run as SYSTEM, then it will not see network printers.
Again, I suppress program notifications because of the frequency of the program but that is up to you.

5) Advertise the REGINI program: This program is needed to set up the registry structure and permissions before the vbs is run. I am advertising this with a mandatory assignment of every 5 days. This is a very lightweight command and will not interfere with any data in place.

6) Advertise the VBS: The VBS will pick up all printers and information about the logged in user (including RDP users!) and write that to the registry keys. The script currently ignores all Microsoft printers, but it can be altered easily to ignore other printers such as Adobe. I also use a possibility of 50 mapped printers. This can also be modified by deleting or adding rows in the REGINI file and modifying the script’s loops to the new amount. Believe it or not, I actually had users with this many mapped printers, and I did not want to miss any data. I set a mandatory assignment time of every 3 hours in order to collect as much data as I can. However, the data in the registry keys is not uploaded until the next hardware inventory cycle.

7) Import the reports: I created (and attached) several reports that you can import to get data for specific collections, specific users, specific computers, all local printers, all network printers, and all default printers. If you choose not to use these, then you can find the information in the v_gs_PrinterInv0 table on your SCCM SQL database.

Conclusion:
It was important that I share this solution with everyone so that more people can take advantage of it. I wrote a lot of the scripts myself, but I gave credit within the script to a couple of reference scripts that were used to determine WMI locations and RDP users.

email

Written by , Posted .
  • http://myITforum.com/myitforumwp/community/members/jrsexton/ Jason Sexton

    I don’t see that table in my SQL database. Is there something I am missing?

  • Oleg

    I don’t see anything in registry.

    What may be wrong?