header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
get-wmiobject win32_printer name includes twice as many "\"?
Last Post 11 Aug 2010 08:32 AM by Ryan32. 5 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Ryan32User is Offline
New Member
New Member
Posts:21
Avatar

--
27 Jul 2010 12:54 PM
    I'm somewhat of a powershell newbie here, so I apologize if this is a ridiculous question:  Why does the printer name of a network printer show up as "\\\\printserver.domain.com\\printername" when using get-wmiobject win32_printer?

    Why all the extra "\"?

    This had me confused for the longest time as I was writing a script to remove printers and re-add different ones...  I now have it working, but still have no idea why the extra slashes are added.  Any pointers would be greatly appreciated, i hate not knowing the "why".  :)
    Mihail StacanovUser is Offline
    New Member
    New Member
    Posts:15
    Avatar

    --
    11 Aug 2010 06:33 AM
    #please post you script and show your code, because I can't see the output like yours mine is:

    Get-WmiObject win32_printer -ComputerName PCNAME | ft name

    name
    ----
    Microsoft XPS Document Writer
    Microsoft Office Document Image Writer
    Canon CP660PS
    http://proproit.com
    Ryan32User is Offline
    New Member
    New Member
    Posts:21
    Avatar

    --
    11 Aug 2010 07:43 AM
    Say I run the following:

    Get-WMIObject -query "select * from win32_printer"


    Now that will return a printer name of say "\\printserver1\printer1"

    However if you try to run:

    Get-WMIObject -query "select * from win32_printer where name = '\\printserver1\printer1'"


    It can't find the device.... You have to add in additional "\" for it to work as noted above:

    Get-WMIObject -query "select * from win32_printer where name = '\\\\printserver1\\printer1'"


    And prints off your server just fine. I just don't understand why the name reports as \\printserver1\printer1 when in reality it can't be removed unless you use \\\\printserver1\\printer1

    Hope that makes more sense.
    Mihail StacanovUser is Offline
    New Member
    New Member
    Posts:15
    Avatar

    --
    11 Aug 2010 07:43 AM
    #this is my output
    Get-WMIObject -query "select * from win32_printer"


    Location      :
    Name          : NPIF94A0D (HP LaserJet P2055dn)
    PrinterState  : 0
    PrinterStatus : 3
    ShareName     :
    SystemName    : PC1

    Location      :
    Name          : Adobe PDF
    PrinterState  : 0
    PrinterStatus : 3
    ShareName     :
    SystemName    : PC2

    Please post your "$host.version" command output
    http://proproit.com
    Joel "Jaykul" BennettUser is Offline
    Basic Member
    Basic Member
    Posts:112
    Avatar

    --
    11 Aug 2010 07:54 AM
    This is just a problem with PowerShell's interfacing to other query languages ;-)
    In PowerShell, the backtick is the escape character: `

    But in WQL (WMI Query Language, which you're using in Get-WMIObject) and in regular expressions, and a few other places, the implementation of WMI/WQL and regex is out of the hands of the PowerShell team, being built into the OS or the .Net framework.

    In those cases, the actual query strings use the backslash \ as the escape character, which means that when you want to include a backslash in the text, you have to escape it (with a preceeding backslash). So your output should be "right" and show one slash (or two at the beginning), but your query has to be escaped (so all the slashed get doubled up).

    I guess we should just be glad we don't have to do that with all our PSProvider paths ;-)
    Ryan32User is Offline
    New Member
    New Member
    Posts:21
    Avatar

    --
    11 Aug 2010 08:32 AM
    Thank you!  That makes sense.   The more I learn about powershell and it's capabilities, the more I love it....

    We're now running a production login script to map client printers based on AD security groups using powershell...  Works like a charm!  :)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer