确定哪个组策略适用于哪台打印机

确定哪个组策略适用于哪台打印机

因此在工作中会有数千台打印机和数百个打印机组策略组。

我如何确定哪个组将部署哪台打印机?

请忽略命名约定等。

我想知道有哪些方法可以实现,我在网上查过,大多数建议是使用组策略部署打印机,但这不是我所需要的。

答案1

我无法访问像您这样的域,但以下是我发现的内容。我假设您在域内使用 Windows,因此最好的工具是 PowerShell。

文章 获取 Active Directory 域中发布的打印机列表 有此 PowerShell 命令行来获取域中的打印服务器和打印机列表:

Get-ADObject -LDAPFilter "(objectCategory=printQueue)" -Properties cn, drivername, location, printername, portname, servername | select portname, cn, drivername, location, printername, servername | Format-Table -Property * -AutoSize | Out-String -Width 4096 | Out-File C:\wisefaq\printerlist.txt

另一篇有用的文章是 使用 WMI 从计算机获取打印机名称、IP 地址和驱动程序 其中包含一个 PowerShell 脚本,需要输入域中的打印机服务器列表:

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

要识别 GPO 和打印机,请参阅文章 使用 PowerShell 获取所有部署 GPO 的打印机脚本本身太长了,但我还是在这里列出来。您可以在文章中找到有关其使用的说明。

获取 GPOPrinters.ps1

<#
.SYNOPSIS     
The script finds all shared printers deployed with GPO (both deployed printers GPP.) in your domain. 
.NOTES     
           File Name: Get-GPOPrinters.ps1     
           Author   : Johan Dahlbom, johan[at]dahlbom.eu     
           The script are provided “AS IS” with no guarantees, no warranties, and it confer no rights. 
           Blog     : 365lab.net
#>
#Import the required module GroupPolicy
try
{
Import-Module GroupPolicy -ErrorAction Stop
}
catch
{
throw "Module GroupPolicy not Installed"
}
$GPO = Get-GPO -All

foreach ($Policy in $GPO){

        $GPOID = $Policy.Id
        $GPODom = $Policy.DomainName
        $GPODisp = $Policy.DisplayName
        $PrefPath = "\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences"

            #Get GP Preferences Printers
            $XMLPath = "$PrefPath\Printers\Printers.xml"
            if (Test-Path "$XMLPath")
            {
                 [xml]$PrintXML = Get-Content "$XMLPath"

                        foreach ( $Printer in $PrintXML.Printers.SharedPrinter )

                            {New-Object PSObject -Property @{
                                GPOName = $GPODisp
                                PrinterPath = $printer.Properties.Path
                                PrinterAction = $printer.Properties.action.Replace("U","Update").Replace("C","Create").Replace("D","Delete").Replace("R","Replace")
                                PrinterDefault = $printer.Properties.default.Replace("0","False").Replace("1","True")
                                FilterGroup = $printer.Filters.FilterGroup.Name
                                GPOType = "Group Policy Preferences"
                            }
                        }
           }
           #Get Deployed Printers
           [xml]$xml = Get-GPOReport -Id $GPOID -ReportType xml
           $User = $xml.DocumentElement.User.ExtensionData.extension.printerconnection
           $Computer = $xml.DocumentElement.computer.ExtensionData.extension.printerconnection

                foreach ($U in $User){
                    if ($U){

                            New-Object PSObject -Property @{
                                GPOName = $GPODisp
                                PrinterPath = $u.Path
                                GPOType = "GPO Deployed Printer - User"
                            }
                    }

                }

                foreach ($C in $Computer){
                    if ($c){

                            New-Object PSObject -Property @{
                                GPOName = $GPODisp
                                PrinterPath = $c.Path
                                GPOType = "GPO Deployed Printer - Computer"
                            }
                    }

                }
}

相关内容