Is there a way to find out what printers a user has mapped remotely?

64

Solution 1

Well, you can take a look at the Win32_Printer WMI class,

Get-WMIObject Win32_Printer -ComputerName $Comp

But, I think this will get you even better results:

New-PSSession $Comp | Enter-PSSession
Get-ChildItem Registry::\HKEY_Users\$UserSID\Printers\Connections
Exit

Without using PS Remoting, you could do this instead:

$Printers = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(Microsoft.Win32.RegistryHive]::Users, $ServerName)

You get the idea. Basically, you need to access that user's registry key with whatever method and enumerate whatever you find in Printers\Connections.

Solution 2

For anyone that's interested in what working code looks like to enumerate the accounts and get a listing of the installed printers, please see below:

Get-ChildItem Registry::\HKEY_Users | 
Where-Object { $_.PSChildName -NotMatch ".DEFAULT|S-1-5-18|S-1-5-19|S-1-5-20|_Classes" } | 
Select-Object -ExpandProperty PSChildName | 
ForEach-Object { Get-ChildItem Registry::\HKEY_Users\$_\Printers\Connections -Recurse | Select-Object -ExpandProperty Name }

This snippet first enumerates all subkeys under HKEY_Users, it then filters out the default/system account keys and the Classes keys for each user, finally it enumerates each remaining key's \Printers\Connections subkeys to output the printer information to the console.

Kudos to Ryan, so thought I would contribute via an answer.

Share:
64

Related videos on Youtube

Rohan Arthur
Author by

Rohan Arthur

Updated on September 18, 2022

Comments

  • Rohan Arthur
    Rohan Arthur almost 2 years

    Say I have 2 google sheets: sheet1 and sheet2. My dream is as follows:

    1. create two email addresses for these sheets, say [email protected] and [email protected] respectively
    2. When I send an email to [email protected] from anywhere, the content of that email is created as a new row in sheet1
    3. Likewise for [email protected] and sheet2

    Is this possible?

    I tried searching for a solution, but could find only articles about how to send emails FROM sheets, and not TO sheets.

  • kralyk
    kralyk over 10 years
    +1, and just for grins, check this link: powershell.com/cs/media/p/16643.aspx since they try to get all fancy with voice, etc.
  • MDMoore313
    MDMoore313 over 10 years
    The gci Registry::\.... is about to roll up nicely into a powershell function, fyi.