Get printer names, IP addresses and drivers from a computer using WMI.

kickapoos 1 Reputation point
2021-04-06T18:44:34.06+00:00

Hello,
I found the following PowerShell script in this forum, it works very well. Is it possible to export the users and groups of the installed printers.
If possible, not the SID but the username in plain text

$ReportFileName = "c:\printerreport.csv" 
$PrintServersList="c:\PrintServersList.txt" 

$servers =  Get-Content -Path $PrintServersList 
$allprinters = @() 
foreach( $server in $servers ){ 
Write-Host "checking $server ..." 
$printers = $null 
$printers = Get-WmiObject -class Win32_Printer -computername $server | select Name,Shared,ShareName,Local, DriverName, PortName,@{n="PrinterIp";e={(((gwmi win32_tcpipprinterport -ComputerName $server -filter "name='$($_.PortName)'") | select HostAddress).HostAddress)}},@{n='PrintServer';e={$_.SystemName}}, Location,Comment,SpoolEnabled,Published
$allprinters += $printers 
 } 
 Write-Host "exporting to printers.csv" 
$allprinters | Export-CSV -Path $ReportFileName -NoTypeInformation -Force -Encoding UTF8
Write-Host "Done!"
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,377 questions
{count} votes

7 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,891 Reputation points Microsoft Vendor
    2021-04-09T15:00:18.637+00:00

    Hi,

    This will remove the duplicate trustee names.

     $ReportFileName = "C:\printerreport.csv"   
     $PrintServersList="C:\PrintServersList.txt"           
     $servers =  Get-Content -Path $PrintServersList   
     $allprinters = @()    
     foreach( $server in $servers ){   
     Write-Host "checking $server ..."   
     $printers = $null   
     $printers = Get-WmiObject -class Win32_Printer -computername $server |   
         select Name,Shared,ShareName,Local, DriverName, PortName,  
         @{n="PrinterIp";e={(((gwmi win32_tcpipprinterport -ComputerName $server -filter "name='$($_.PortName)'") | select HostAddress).HostAddress)}},  
         @{n='PrintServer';e={$_.SystemName}}, Location,Comment,SpoolEnabled,Published,  
         @{n='Trustee Name';e={(($_.GetSecurityDescriptor()).Descriptor.DACL.Trustee.Name | Select-Object -Unique) -join ','}}  
         @{n='Trustee SID';e={($_.GetSecurityDescriptor()).Descriptor.DACL.Trustee.SIDString -join ','}}  
         $allprinters += $printers    
       }       
     Write-Host "exporting to printers.csv"   
     $allprinters | Export-CSV -Path $ReportFileName -NoTypeInformation -Force -Encoding UTF8  
     Write-Host "Done!"  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. ARoad13 1 Reputation point
    2021-11-03T17:46:51.947+00:00

    Is this to be run from the printer server itself?

    I have to export driver information from around 150 print servers across the state. I would like to find a script that will grab all this info without logging into every print server and doing an export.