question

kickapoos avatar image
0 Votes"
kickapoos asked RichMatheisen-8856 commented

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

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
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
The script gets the printers attached to the servers. Could you clarify what users and groups you want to export?

0 Votes 0 ·

Hi,
Is there any update? Have you got a chance to verify the below suggestions?
Please feel free to let us know if more assistance is needed. If the reply is helpful, please “Accept Answer” to help other community members find it more easily.

0 Votes 0 ·
kickapoos avatar image
0 Votes"
kickapoos answered

Hi,

The users and groups of the printers found are to be exported to c: \ printerreport.csv.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

Hi,

Do you want to get the names in the security tab? If so you can try something like this

 $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 -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!"

Note that some of the trustees have no name.

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

kickapoos avatar image
0 Votes"
kickapoos answered

Hi IanXue-MSFT,

Great !!!

Thank you, all entries are in the CSV.
At the end, two errors are displayed


 checking  ...
 Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null 
 or empty, and then try the command again.
 At C:\printerlistexport_acl.ps1:9 char:63
 + ... printers = Get-WmiObject -class Win32_Printer -computername $server |
 +                                                                 ~~~~~~~
     + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
     + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
     
 exporting to printers.csv
 Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
 At C:\printerlistexport_acl.ps1:19 char:17
 + ... lprinters | Export-CSV -Path $ReportFileName -NoTypeInformation -Forc ...
 +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
     + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand
     
 Done!
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

Hi,

The error message indicates the last element of $servers is empty. Please check if there's a blank line at the end of PrintServersList.txt.

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

kickapoos avatar image
0 Votes"
kickapoos answered

Hi,

I removed the space in PrintServersList.txt, it works.

The admin,,ALL APPLICATION PACKAGES,,CREATOR_Owner,Administrators are duplicated in printerreport.csv.

The authorization list from the printer shows

ALL APPLICATION PACKAGES = doc_manage and print
S-1-15-3-1024 = doc_manage and print
CREATOR_Owner = doc_manage
ADMIN = full
Administrators = full
hx-101= print

In the printerreport.csv

 Trustee Name
 hx-101,admin,admin,CREATOR_Owner,ALL APPLICATION PACKAGES,ALL APPLICATION PACKAGES,ALL APPLICATION PACKAGES,Administrators,Administrators,,,

I also tested it on different 2019 servers




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ARoad13-3162 avatar image
0 Votes"
ARoad13-3162 answered RichMatheisen-8856 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That script queries remote servers whose names are in a file.

0 Votes 0 ·