ip address to get printer property

Welcome Forums General PowerShell Q&A ip address to get printer property

Viewing 10 reply threads
  • Author
    Posts
    • #229261
      Participant
      Topics: 1
      Replies: 5
      Points: 24
      Rank: Member

      Hi ,

      New here and to PowerShell .

      Was looking to get help with an issue. We have a few printers on the network and was trying to get status on them via ipaddress .

      I had tried this

      $pn = $null
      $pn = Get-Content “.\printersnoton.txt”
      $allprinters = @()
      foreach( $pn in $pn ){
      Write-Host “checking $Printer …”
      $printer = $null
      $printers = $null
      $printers = Get-Printer -name {$_. $pn}
      $printer = $printers | where-object {$_.shared}
      #| select-object sharename, DriverName, PortName, SystemName, Location | Export-CSV .\printers3.csv
      $allprinters += $printer
      }
      Write-Host “exporting to printers3.csv”
      $allprinters | select-object name, DriverName, PortName, Location, Printerstaus | Export-CSV .\printers3.csv -NoTypeInformation
      Write-Host “Done!”

      but get into trouble over the ip address ….any help will be appreciated.

      Thanks John B

       

    • #229279
      Participant
      Topics: 12
      Replies: 1610
      Points: 2,508
      Helping Hand
      Rank: Community Hero

      jbarreiro81, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      Let’s start with exactly what you’re trying to accomplish with the code posted. You have a list of printer names. You want to get all printers (assume a print server) and then get the details of the printers in the list? Take a look at this simplified code:

      #List of printer names
      $pn = Get-Content “.\printersnoton.txt”
      #Assuming this is run on a print server with all printers
      $allPrinters = Get-Printer
      #Get all of the printers in the printer list
      $printersInList = $allPrinters | Where{$pn -contains $_.Name}
      

      Next you want the IP of the printer, that should be in the PortName, but let’s start with the basics of what you are trying to do above and then talk about the IP Address.

    • #229300
      Participant
      Topics: 1
      Replies: 5
      Points: 24
      Rank: Member

      Oops

       

      $pn = $null
      $pn = Get-Content “.\printersnoton.txt”
      $allprinters = @()
      foreach( $pn in $pn ){
      Write-Host “checking $Printer …”
      $printer = $null
      $printers = $null
      $printers = Get-Printer -name {$_. $pn}
      $printer = $printers | where-object {$_.shared}
      # select-object sharename, DriverName, PortName, SystemName, Location | Export-CSV .\printers3.csv
      $allprinters += $printer
      }
      Write-Host “exporting to printers3.csv”
      $allprinters | select-object name, DriverName, PortName, Location, Printerstaus | Export-CSV .\printers3.csv -NoTypeInformation
      Write-Host “Done!”

      How does that look?

      Any way trying to get info for printers not on a printserver.

      In the printersnoton.txt file is a list of ip addresses . I fI look for the printer name it never find it because it is not local to my machine.

      Thanks

      John B.

    • #229306
      Participant
      Topics: 1
      Replies: 5
      Points: 24
      Rank: Member

      Oops I have done it wrong again …
      This is what I use for getting info from print servers …

      `$servers = Get-Content “.\server-list.txt”
      $allprinters = @()
      foreach( $server in $servers ){
      Write-Host “checking $server …”
      $printer = $null
      $printers = $null
      $printers = Get-Printer -computername $server
      $printer = $printers | where-object {$_.shared}
      #| select-object sharename, DriverName, PortName, Location, printerstatus | Export-CSV .\process.csv
      $allprinters += $printer
      }
      Write-Host “exporting to printers.csv”
      $allprinters | select-object sharename, DriverName, PortName, Location, printerstatus | Export-CSV .\printers.csv -NoTypeInformation
      Write-Host “Done!”

      again sorry for that hope this comes out ok!

    • #229315
      Participant
      Topics: 12
      Replies: 1610
      Points: 2,508
      Helping Hand
      Rank: Community Hero

      Still incorrect on the code, please re-read the instructions. You have a printer IP address, that according the the naming is not working? The printer is installed on the system where Get-Printer is being run? If you look at the PortName (or other column), do you see the IP address you’re searching for? If I wanted to find something, you would see how you can filter. Below you list Name and PortName and then find something that has the number in it:

      PS C:\Users\rasim> Get-Printer | Select Name, PortName
      
      Name                          PortName                                                                                                                          
      ----                          --------                                                                                                                          
      Send To OneNote               nul:                                                                                                                              
      Snagit 2020                   C:\ProgramData\TechSmith\Snagit 20\PrinterPortFile                                                                                
      OneNote for Windows 10        Microsoft.Office.OneNote_16001.12730.20190.0_x64__8wekyb3d8bbwe_microsoft.onenoteim_S-1-5-21-2370741873-3768727752-2996739931-1001
      Microsoft XPS Document Writer PORTPROMPT:                                                                                                                       
      Microsoft Print to PDF        PORTPROMPT:                                                                                                                       
      Fax                           SHRFAX:                                                                                                                           
      Canon TS9100 series           WSD-e189f362-50bd-44e0-9539-ba4820a552c0                                                                                          
      
      
      
      PS C:\Users\rasim> Get-Printer | Where{$_.PortName -like '*01.12730.20190*'}
      
      Name                           ComputerName    Type         DriverName                PortName        Shared   Published  DeviceType     
      ----                           ------------    ----         ----------                --------        ------   ---------  ----------     
      OneNote for Windows 10                         Local        Microsoft Software Pri... Microsoft.Of... False    False      Print   
      

      Try to find one IP in the PortName and then we can look at how to search with a list

    • #229480
      Participant
      Topics: 1
      Replies: 5
      Points: 24
      Rank: Member

      Thanks Rob but maybe using the wrong command? The printers are at another location and are used by 2 or 3 people there.
      So they are on the network but not on a printserver , sort of stand alone . My point is that maybe get-printer is not what I should be using
      since that network is no a different segment . I also did not want to add it to my PC so I can then get the status and info I was trying to get.
      Thanks for all your help not used to sending out and looking for help elsewhere… sorry for not knowing what to do but just started trying powershell. I also have not been trained…

    • #229498
      Participant
      Topics: 3
      Replies: 324
      Points: 1,056
      Helping Hand
      Rank: Community Hero

      If you’re trying to query the printers directly, perhaps you should look at SNMP? Are you not able to query the printers via one of the computers there that have it installed? Even though they may not be “servers,” they can still act like a print server.

    • #229501
      Participant
      Topics: 1
      Replies: 5
      Points: 24
      Rank: Member

      Was trying not to go to the other computers to get the info . Trying to get it directly from printers. I will look into SNMP though.
      Thanks for the input.

    • #229675
      Participant
      Topics: 12
      Replies: 1610
      Points: 2,508
      Helping Hand
      Rank: Community Hero

      If they are standalone printers and all you have is an IP, there isn’t much you can do outside of a simple ping to see if the IP is responding. A list of IP’s like so:

      printersnoton.txt

      8.8.8.8
      9.9.9.9
      10.10.123.123
      

      YOu can check status with Test-Connection:

      #List of printer names
      $pn = Get-Content “.\printersnoton.txt”
      $pn | Select @{Name='IP';Expression={$_}}, @{Name='Online';Expression={Test-Connection -ComputerName $_ -BufferSize 16 -Count 1 -Quiet}}
      

      Output:

      IP            Online
      --            ------
      8.8.8.8         True
      9.9.9.9         True
      10.10.123.123  False
      
    • #229807
      Participant
      Topics: 1
      Replies: 5
      Points: 24
      Rank: Member

      Thanks Rob ,
      So there is nothing I can use to pass the ip address to so that I can view info ….
      tried other things that ask for computer name , but would not respond to the printer name such as ADG HP 610 ….
      OK at least I can find out if it is online…

      Thanks for your help greatly appreciate it.

    • #229819
      Participant
      Topics: 12
      Replies: 1610
      Points: 2,508
      Helping Hand
      Rank: Community Hero

      The Printers aren’t running a Windows OS. Most of the printer validation scripts are executed on a Windows server acting as a print server hosting queues, which is where Get-Printer or WMI Win32_Printer is applicable. This is normal in corporate environments accessing a queue \\prtsrv1\Bldg2ColorPtr or something like that. If the printer has an IP address just assigned to a network card and it is being accessed by IP on the end points by installing a driver only, then the printer needs to be queried by management software by the manufacturer which is going to use SNMP as Doug eluded above.

Viewing 10 reply threads
  • You must be logged in to reply to this topic.