none
Get user's mapped printers - Powershell invoke-command vs psexec

    Question

  • Hi Scripting Guys!

    These two commands give different outputs, and i don't understand why. The goal is to get a list of mapped printers in a user session. (i.e. \\ps\printername)

    This one only returns local installed printers:

    Invoke-Command -ComputerName <ComputerName> -Credential <domain\user> -ScriptBlock {Get-Wm
    iObject win32_printer | select-object name}


    This one returns what I'm looking for:

    psexec \\<ComputerName> -u <domain\user> wmic printer get name

    Why?

    Thank you,


    Francesco B.

    • Moved by Bill_Stewart Tuesday, May 30, 2017 8:16 PM This is not "research differences between psexec and wmi for me" forum
    Friday, April 14, 2017 2:31 PM

All replies

  • What happens if instead of using Invoke-Command you use the -ComputerName parameter in the Get-WmiObject cmdlet?

    Get-WmiObject win32_printer -Computername <ComputerName> -Credential $cred | select-object name

    Tuesday, April 18, 2017 5:15 PM
  • Same behavior. Follow stamps with outputs of the queries made with both the methods.


    Francesco B.




    Wednesday, April 19, 2017 7:57 AM
  • You cannot remotely get mapped printers.  This has always been true in Windows.


    \_(ツ)_/

    Wednesday, April 19, 2017 8:01 AM
  • You cannot remotely get mapped printers.  This has always been true in Windows.


    \_(ツ)_/


    As you can see above, with psexec and wmic I can see mapped printers. I would expect that with invoke-command cmdlet in powershell, I'd have to get the same info.

    Francesco B.

    Wednesday, April 19, 2017 8:04 AM
  • Only admins can use WMI remotely so it is hard to understand what you are trying to accomplish.


    \_(ツ)_/

    Wednesday, April 19, 2017 8:07 AM
  • Only admins can use WMI remotely so it is hard to understand what you are trying to accomplish.


    \_(ツ)_/

    What do you mean? I am an IT admin and I am checking if printers are mapped correctly. Since mapped printers are related to the current user session, I need to specify user credential to accomplish it. So I can get it with psexec and wmic combination, but not with powershell invoke-command get-wmiobject. I don't understand the reason.

    Francesco B.


    Wednesday, April 19, 2017 8:13 AM
  • WMI can only be accessed remotely by an admin by default.

    PsExec uses a different kind of session and can connect as a non-admin user which is why it is considered to be a security risk.


    \_(ツ)_/

    Wednesday, April 19, 2017 8:26 AM
  • Note also that PsExec is like RDS. It logs into the remote system with a full session.  WMI does not.


    \_(ツ)_/

    Wednesday, April 19, 2017 8:26 AM
  • We are going OT and you are not answering to my question.

    Anyway in my case, for my goal, WMI is used either with psexec that runs wmic or with Invoke-Command that runs Get-WmiObject on the remote pc, both executed by providing user credentials. So WHY does the first command returns mapped printers and not instead the other command?


    Francesco B.

    Wednesday, April 19, 2017 8:34 AM
  • PS: Also Get-WmiObject cmdlet has a parameter "-Credential", I suppose for getting user session related information. Even with it I get only local printers. 

    Francesco B.


    Wednesday, April 19, 2017 8:39 AM
  • PS: Also Get-WmiObject cmdlet has a parameter "-Credential", I suppose for getting user session related information. Even with it I get only local printers. 

    Francesco B.


    Take some time to learn WMI and PowerShell remoting.  The credentials are used to authenticate and not to get a users session.


    \_(ツ)_/

    Wednesday, April 19, 2017 8:53 AM
  • What do you say instead about Enter-PSSession cmdlet?
    Isn't there then a powershell method psexec equivalent?

    Francesco B.

    Wednesday, April 19, 2017 10:30 AM