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.