📜 ⬆️ ⬇️

PowerShell and Group Policy Preferences, when the printers account for hundreds



Many copies are broken around managing network printers on user computers. In general, administrators have split into two camps: connecting logon scripts (bat / vbs) and managing via GPP. Both approaches have their advantages: scripts are processed faster, and GPP is more flexible and is used more often than users restart computers. But when there are more than a hundred printers and they are scattered in several dozen offices and cities, the difficulties will be in both cases.

It is necessary not only to connect the correct set of printers to each user, given his current location, but also not to forget about one. And if sometimes not only users move, but the printers themselves ...
')
In general, my colleagues and I chose GPP for ourselves, primarily so that someone other than the leading administrators could figure out the current config, just by looking at the GPMC report. However, who can say that its staff interface is convenient for managing 100+ devices - let the first one throw a stone at me. In addition, when commissioning the next batch, you need to do a lot of routine on setting up network scanning and adding to the print server.

And everything that is done more than once can be automated!

What are we going to do today?


So, let's begin.

1. Accounting network printers


The first problem that arises when managing a large number of any objects is accounting. Without it, it is easy to get confused about what is installed and to whom it should be connected.
The simplest and most versatile solution is CSV. In the end, from any inventory system, ServiceDesk or Excel spreadsheet you can upload to CSV and then easily import it into PowerShell, which we will do next.

Our unloading looks like this:

image

I will explain right away why so many fields:


This dataset is enough not to hardcode them in Powershell. You can start the fun.

2. Automate GPP


In general, the Printers.xml file in a GPP object looks like this:

<?xml version="1.0" encoding="utf-8"?> <Printers clsid="{1F577D12-3D1B-471e-A1B7-060317597B9C}"> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BARAB-061" status="PRN-BARAB-061" image="2" uid="{43231EA0-A4A3-4F1A-8A25-95BC4FEFBCC6}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-BARAB-061" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-BARAB-061" sid="S-1-5-21-210359847-7924152125-768726458-48993" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.142.1" max="192.168.142.254" /> </Filters> </SharedPrinter> </Printers> 

The source of the format can be explored here: [MS-GPPREF]: Printers and here: [MS-GPPREF]: Common XML Attributes .

Practically, I think you can easily match the field names in this file with the checkboxes in the GPP interface, but I’ll note the key points:

clsid are the fixed values ​​of the Group Policy Preferences classes, you can (and should) leave them as they are.

Name / Status is the display names of the items in the GPP console.
uid - and here is the unique identifier of the object that you saw in the table above.

If it changes every time the list of printers is updated, the printer will reconnect to all users, which can cause different side effects.
Path - UNC path to the printer
FilterGroup, FilterIpRange - Targeting elements by user membership in the AD group and by finding the computer in the range of IP addresses.

2.1. We import the data and create the basic structure of the XML document:


To do this, use the system class [System.Xml.XmlDocument]:

 $PrintersCSV = Import-Csv -Delimiter ";" ".\Printers.csv" -Encoding Default [System.Xml.XmlDocument]$PrintersGPP = New-Object System.Xml.XmlDocument $PrintersGPP.PrependChild($PrintersGPP.CreateXmlDeclaration("1.0", "utf-8", $null)) | Out-Null $Printers = $PrintersGPP.AppendChild($PrintersGPP.CreateElement("Printers")) $Printers.SetAttribute("clsid","{1F577D12-3D1B-471e-A1B7-060317597B9C}") 

2.2. Add a few helper functions to create the required XML elements and set their attributes.


Creating a printer item:

 Function NewSharedPrinter { [CmdletBinding()] param ( $SharedPrinter, $clsid = "{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}", $uid, $name, $action ) $image switch ($action){ "C" {$image = 0} "R" {$image = 1} "U" {$image = 2} "D" {$image = 3} } $SharedPrinter.SetAttribute("clsid",$clsid) $SharedPrinter.SetAttribute("name",$name) $SharedPrinter.SetAttribute("status",$name) $SharedPrinter.SetAttribute("image",$image) $SharedPrinter.SetAttribute("uid",$uid) $SharedPrinter.SetAttribute("userContext",1) $SharedPrinter.SetAttribute("bypassErrors",1) $SharedPrinterProperties = $SharedPrinter.AppendChild($PrintersGPP.CreateElement("Properties")) $SharedPrinterProperties.setattribute("action",$action) $SharedPrinterProperties.setattribute("comment","") $SharedPrinterProperties.setattribute("path","\\print-cluster-1.common.domain\$name") $SharedPrinterProperties.setattribute("default",0) $SharedPrinterProperties.setattribute("port","") } 

Creating filtering elements (targeting) by group and by subnet:
 Function NewFilterGroup{ [CmdletBinding()] param ( $FilterGroup, $bool = "AND", $not = 0, $name, $sid ) $FilterGroup.SetAttribute("bool",$bool) $FilterGroup.SetAttribute("not",$not) $FilterGroup.SetAttribute("name","COMDOM\"+$name) $FilterGroup.SetAttribute("sid",$sid) $FilterGroup.SetAttribute("userContext",1) } Function NewFilterSubnet{ [CmdletBinding()] param ( $FilterIPRange, $bool = "AND", $not = 0, $start, $end ) $FilterIPRange.SetAttribute("bool",$bool) $FilterIPRange.SetAttribute("not",$not) $FilterIPRange.SetAttribute("min",$start) $FilterIPRange.SetAttribute("max",$end) } 

All three functions work directly with the transmitted PS object and return nothing. Remark for perfectionists: at the time of writing the script it was easier and faster, I did not want to write the perfect object-oriented code, I just needed it to work. So yes, the code has something to improve, but the main thing is that it works!

2.3. Finally, the main loop, adding controls to printers


Two elements are created for each printer: one to add if the user is in a group and on the subnet, and one to delete the printer if the user is not in the group or is on a different subnet.

If for some reason there is no printer UID in the CSV file, it will be generated and output to the console.

To translate the subnet from the CIDR notation to the address range, I borrowed the wonderful PSipcalc cmdlet.

 ForEach ($PrinterItem in ($PrintersCSV | Sort-Object Name)) { if (!$PrinterItem.uid){ $uid = "{"+([guid]::NewGuid()).Guid.ToUpper()+"}" Write-Host "Printer $($PrinterItem.Name) is new. Policy item ID: $uid" } else { $uid = $PrinterItem.uid } $SharedPrinter = $PrintersGPP.CreateElement("SharedPrinter") NewSharedPrinter -SharedPrinter $SharedPrinter -name $PrinterItem.Name -action "U" -uid $uid $Filters = $SharedPrinter.AppendChild($PrintersGPP.CreateElement("Filters")) if ($PrinterItem.ByGroup -ieq "yes") { try { Get-ADGroup -Identity $PrinterItem.Name | Out-Null } catch { Write-Host "Creating group $($PrinterItem.Name)" New-ADGroup -Name $PrinterItem.Name ` -Path "OU=    ,OU=User Groups,DC=DOM,DC=COM" -GroupScope DomainLocal } $FilterGroup = $PrintersGPP.CreateElement("FilterGroup") NewFilterGroup -FilterGroup $FilterGroup -name $PrinterItem.Name -sid (Get-ADGroup -Identity $PrinterItem.Name).SID.Value $Filters.AppendChild($FilterGroup) | Out-Null } $FilterNetwork = .\PSipcalc.ps1 -NetworkAddress $PrinterItem.Subnet $FilterIPRange = $PrintersGPP.CreateElement("FilterIpRange") NewFilterSubnet -FilterIPRange $FilterIPRange -start $FilterNetwork.HostMin -end $FilterNetwork.HostMax $Filters.AppendChild($FilterIPRange) | Out-Null $Printers.AppendChild($SharedPrinter) | Out-Null $RevertSharedPrinter = $PrintersGPP.CreateElement("SharedPrinter") NewSharedPrinter -SharedPrinter $RevertSharedPrinter -name $PrinterItem.Name -action "D" -uid $uid if ($PrinterItem.ByGroup -ieq "yes") { $bool = "OR" } else { $bool = "AND" } $Filters = $RevertSharedPrinter.AppendChild($PrintersGPP.CreateElement("Filters")) if ($PrinterItem.ByGroup -ieq "yes") { $FilterGroup = $PrintersGPP.CreateElement("FilterGroup") NewFilterGroup -FilterGroup $FilterGroup -name $PrinterItem.Name -sid (Get-ADGroup -Identity $PrinterItem.Name).SID.Value -bool "AND" -not 1 $Filters.AppendChild($FilterGroup) | Out-Null } $FilterIPRange = $PrintersGPP.CreateElement("FilterIpRange") NewFilterSubnet -FilterIPRange $FilterIPRange -start $FilterNetwork.HostMin -end $FilterNetwork.HostMax -bool $bool -not 1 $Filters.AppendChild($FilterIPRange) | Out-Null $Printers.AppendChild($RevertSharedPrinter) | Out-Null } 

2.4. And now we output the result to a file.


I see nothing wrong with saving a few minutes and immediately writing to the policy:

 $PrintersGPP.Save("\\COMDOM\SysVol\COMMON.DOMAIN\Policies\{f985a9ae-cb71-468b-8a99-e2c7f428aa2f}\User\Preferences\Printers\Printers.xml") 

3. Adding Printers to a Print Server


On Windows, there is a rather obscure set of vbs-scripts for managing printers. And it is even in the client versions. It is located in the directory %SystemRoot%\System32\Printing_Admin_Scripts\en-US , Murzilka can be read here .

We are interested in three utilities from the set:

prnport.vbs - to create a printer port on the print server
prnmngr.vbs - to create the printer itself
prncnfg.vbs - for setting preferences and enabling printer sharing
We will also need the SetACL utility to set access rights to printers.

3.1. Create a printer on the print server


To do this, create a script CreateRemotePrinter.bat.

As arguments, it will take, in order:
% 1 - Printer name;
% 2 - driver name;
% 3 - Location;
% 4 - Description of the printer.

 @echo off SET PRTOOLS="c:\Windows\System32\Printing_Admin_Scripts\en-US" SET SETACL="SetACL.exe" cscript /nologo %PRTOOLS%\prnport.vbs -s print-cl-node-1 -a -r %1 -h %1.common.domain -t -o raw -me cscript /nologo %PRTOOLS%\prnmngr.vbs -s print-cl-node-1 -a -p %1 -m %2 -r %1 cscript /nologo %PRTOOLS%\prncnfg.vbs -s print-cl-node-1 -t -p %1 -h %1 -l %3 -m %4 +shared %SETACL% -on \\print-cl-node-1\%1 -ot prn -actn ace -ace "n:STN-TN\%1;p:man_docs,print" 

In general, this is enough. But our print server is located on the MSCS cluster, and the above set of vbs-scripts does not work with clusters. Therefore, we have to do something else.

3.2. Transfer the printer from a regular print server to a clustered one.


When accessing a cluster, the scripts in the set above simply create a port and a printer on the current active node, and they do not appear on the cluster. Just in such a case, Microsoft has another tool in store - PrintBRM (Print queue Backup / Recovery / Migration). I did not find official documentation for it, so I am sharing what I have: Help for parameters on SS64 .

We continue the CreateRemotePrinter.bat script.

The PrintBRM utility can correctly copy the printer configuration along with the ports to the cluster, but if you simply make a copy (run with the -b key) and restore (-r), then there will be no miracle.

So now there will be some magic. It is described in detail in the MS Performance Team Blog .
First we back up the printer to temp.printerexport.

Then we unpack into the printerexport subdirectory, delete the LMONS and PRTPROCS directories, and also reset the contents of several XML files. I will not go into details, but these files contain a specific server-specific configuration and prevent the printer from being restored to another server, especially the cluster one.

After that, we pack the edited configuration back into the temp.printerexport file and upload it to the cluster:

 SET PRNBRM="C:\Windows\System32\spool\tools\PrintBrm.exe" %PRNBRM% -b -nobin -s print-cl-node-1 -f temp.printerexport %PRNBRM% -r -d printerexport -f temp.printerexport del /f /q temp.printerexport del /s /f /q printerexport\LMONS printerexport\PRTPROCS echo ^<SpoolerAttrib /^> > printerexport\BrmSpoolerAttrib.xml echo ^<PPROCS /^> > printerexport\PProcs.xml echo ^<PRINTERDRIVERS /^> > printerexport\BrmDrivers.xml echo ^<LMONS Arch="Windows x64"/^> > printerexport\BRMLMons.xml %PRNBRM% -b -d printerexport -f temp.printerexport del /s /f /q printerexport %PRNBRM% -r -s print-cluster-1 -f temp.printerexport -p all -o force del /f /q temp.printerexport cscript /nologo %PRTOOLS%\prnmngr.vbs -s print-cl-node-1 -d -p %1 cscript /nologo %PRTOOLS%\prnport.vbs -s print-cl-node-1 -d -r %1 

3.3. Add printers to GPP and server / cluster simultaneously


Now you need to organically enter this script into the CSV-list of printers processing cycle.

Add before the main loop a request for a list of already existing ones on the server:

 $ActualPrintersList = Get-WmiObject -Class win32_share -computer print-cluster-1 | Where-Object Name -like "*PRN*" | Select-Object -ExpandProperty Name 

And in the body of the cycle we will launch our Bat-niche:

  if ("\\print-cluster-1\$($PrinterItem.Name)" -NotIn $ActualPrintersList) { Write-Host "Adding printer $($PrinterItem.Name) to print-cluster-1..." Start-Process -FilePath .\CreateRemotePrinter.bat -ArgumentList "$($PrinterItem.Name) `"$($PrinterItem.Driver)`" `"$($PrinterItem.Location)`" `"$($PrinterItem.Type)`"" -Wait } 

4. Putting it all together, running, we get the result


Raw data in csv
Name;ByGroup;Subnet;Location;Driver;Type;Model;uid
PRN-NALTA-028;yes;192.168.192.0/24;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet Pro M425dn;HP LaserJet Pro M425dn;{35F6CF36-2A24-4A81-B061-8BE71CEC27EA}
PRN-TARUS-002;yes;192.168.128.0/23;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet M3027 MFP;HP LaserJet M3027 MFP;{398F4A94-530C-4E3B-8A30-4288D5E8854D}
PRN-KIRILL-081;;192.168.196.0/24;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet 3390;HP LaserJet 3390;{421FC2DE-2E97-49FC-AEB0-3070B0166AD5}
PRN-BARAB-061;yes;192.168.142.0/24;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet Pro M425dn;HP LaserJet Pro M425dn;{43231EA0-A4A3-4F1A-8A25-95BC4FEFBCC6}
PRN-PYSHM-004;;192.168.143.0/24; /;KX DRIVER for Universal Printing; 4 — Kyocera ECOSYS M2540dn;Kyocera ECOSYS M2540dn;{45509B48-E7BC-4497-9665-86D4E1E96FE1}
PRN-BUY---001;yes;192.168.44.0/24;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet Pro M402dn;HP LaserJet Pro M402dn;{457DB3FE-E35F-450E-B1D6-912F0D831573}
PRN-BATAY-042;yes;192.168.128.0/23;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet P2015 Series;HP LaserJet P2015 Series;{4740604B-C403-4511-91B0-689A197260F3}
PRN-EMPTY-002;yes;192.168.199.0/24;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet Pro M425dn;HP LaserJet Pro M425dn;{475578CB-689F-463B-9710-AE207973146C}
PRN-LIPKI-003;;192.168.44.0/24;/;KX DRIVER for Universal Printing; 4 — Kyocera ECOSYS M2540dn;Kyocera ECOSYS M2540dn;{4794D22E-6586-4A81-A85D-A21FB8B209CF}
PRN-KOTOV-013;yes;192.168.128.0/23;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet Pro M425dn;HP LaserJet Pro M425dn;{4DFFBA1F-48D2-4824-B2EB-0AAD12B6A9D6}
PRN-ELAB-064;;192.168.140.0/24;/;HP Universal Printing PCL 6 (v5.6.0); 4 — HP LaserJet Pro M425dn;HP LaserJet Pro M425dn;{52069D45-EF86-442D-A157-368D7510A1CF}
GeneratePrintersXml.ps1
 $PrintersCSV = Import-Csv -Delimiter ";" ".\Printers.csv" -Encoding Default [System.Xml.XmlDocument]$PrintersGPP = New-Object System.Xml.XmlDocument $PrintersGPP.PrependChild($PrintersGPP.CreateXmlDeclaration("1.0", "utf-8", $null)) | Out-Null $Printers = $PrintersGPP.AppendChild($PrintersGPP.CreateElement("Printers")) $Printers.SetAttribute("clsid","{1F577D12-3D1B-471e-A1B7-060317597B9C}") $DelPrinters = $Printers.AppendChild($PrintersGPP.CreateElement("SharedPrinter")) NewSharedPrinter -SharedPrinter $DelPrinters -name "Delete All" -action "D" -uid "{21097DBD-285D-48C3-B042-7746D7E6DA1B}" $Filters = $DelPrinters.AppendChild($PrintersGPP.CreateElement("Filters")) $FilterRunOnce = $Filters.AppendChild($PrintersGPP.CreateElement("FilterRunOnce")) $FilterRunOnce.SetAttribute("id","{F2537B78-C7D7-43DF-98D6-B32E90644825}") $FilterRunOnce.SetAttribute("hidden",1) $FilterRunOnce.SetAttribute("not",0) $FilterRunOnce.SetAttribute("bool","AND") Function NewSharedPrinter { [CmdletBinding()] param ( $SharedPrinter, $clsid = "{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}", $uid, $name, $action ) $image switch ($action){ "C" {$image = 0} "R" {$image = 1} "U" {$image = 2} "D" {$image = 3} } $SharedPrinter.SetAttribute("clsid",$clsid) $SharedPrinter.SetAttribute("name",$name) $SharedPrinter.SetAttribute("status",$name) $SharedPrinter.SetAttribute("image",$image) $SharedPrinter.SetAttribute("uid",$uid) $SharedPrinter.SetAttribute("userContext",1) $SharedPrinter.SetAttribute("bypassErrors",1) $SharedPrinterProperties = $SharedPrinter.AppendChild($PrintersGPP.CreateElement("Properties")) $SharedPrinterProperties.setattribute("action",$action) $SharedPrinterProperties.setattribute("comment","") $SharedPrinterProperties.setattribute("path","\\print-cluster-1.common.domain\$name") $SharedPrinterProperties.setattribute("default",0) $SharedPrinterProperties.setattribute("port","") } Function NewFilterGroup{ [CmdletBinding()] param ( $FilterGroup, $bool = "AND", $not = 0, $name, $sid ) $FilterGroup.SetAttribute("bool",$bool) $FilterGroup.SetAttribute("not",$not) $FilterGroup.SetAttribute("name","COMDOM\"+$name) $FilterGroup.SetAttribute("sid",$sid) $FilterGroup.SetAttribute("userContext",1) } Function NewFilterSubnet{ [CmdletBinding()] param ( $FilterIPRange, $bool = "AND", $not = 0, $start, $end ) $FilterIPRange.SetAttribute("bool",$bool) $FilterIPRange.SetAttribute("not",$not) $FilterIPRange.SetAttribute("min",$start) $FilterIPRange.SetAttribute("max",$end) } $ActualPrintersList = Get-WmiObject -Class win32_share -computer print-cluster-1 | Where-Object Name -like "*PRN*" | Select-Object -ExpandProperty Name ForEach ($PrinterItem in ($PrintersCSV | Sort-Object Name)) { if (!$PrinterItem.uid){ $uid = "{"+([guid]::NewGuid()).Guid.ToUpper()+"}" Write-Host "Printer $($PrinterItem.Name) is new. Policy item ID: $uid" } else { $uid = $PrinterItem.uid } $SharedPrinter = $PrintersGPP.CreateElement("SharedPrinter") NewSharedPrinter -SharedPrinter $SharedPrinter -name $PrinterItem.Name -action "U" -uid $uid $Filters = $SharedPrinter.AppendChild($PrintersGPP.CreateElement("Filters")) if ($PrinterItem.ByGroup -ieq "yes") { try { Get-ADGroup -Identity $PrinterItem.Name | Out-Null } catch { Write-Host "Creating group $($PrinterItem.Name)" New-ADGroup -Name $PrinterItem.Name ` -Path "OU=    ,OU=User Groups,DC=DOM,DC=COM" -GroupScope DomainLocal } $FilterGroup = $PrintersGPP.CreateElement("FilterGroup") NewFilterGroup -FilterGroup $FilterGroup -name $PrinterItem.Name -sid (Get-ADGroup -Identity $PrinterItem.Name).SID.Value $Filters.AppendChild($FilterGroup) | Out-Null } $FilterNetwork = .\PSipcalc.ps1 -NetworkAddress $PrinterItem.Subnet $FilterIPRange = $PrintersGPP.CreateElement("FilterIpRange") NewFilterSubnet -FilterIPRange $FilterIPRange -start $FilterNetwork.HostMin -end $FilterNetwork.HostMax $Filters.AppendChild($FilterIPRange) | Out-Null $Printers.AppendChild($SharedPrinter) | Out-Null $RevertSharedPrinter = $PrintersGPP.CreateElement("SharedPrinter") NewSharedPrinter -SharedPrinter $RevertSharedPrinter -name $PrinterItem.Name -action "D" -uid $uid if ($PrinterItem.ByGroup -ieq "yes") { $bool = "OR" } else { $bool = "AND" } $Filters = $RevertSharedPrinter.AppendChild($PrintersGPP.CreateElement("Filters")) if ($PrinterItem.ByGroup -ieq "yes") { $FilterGroup = $PrintersGPP.CreateElement("FilterGroup") NewFilterGroup -FilterGroup $FilterGroup -name $PrinterItem.Name -sid (Get-ADGroup -Identity $PrinterItem.Name).SID.Value -bool "AND" -not 1 $Filters.AppendChild($FilterGroup) | Out-Null } $FilterIPRange = $PrintersGPP.CreateElement("FilterIpRange") NewFilterSubnet -FilterIPRange $FilterIPRange -start $FilterNetwork.HostMin -end $FilterNetwork.HostMax -bool $bool -not 1 $Filters.AppendChild($FilterIPRange) | Out-Null $Printers.AppendChild($RevertSharedPrinter) | Out-Null if ("\\print-cluster-1\$($PrinterItem.Name)" -NotIn $ActualPrintersList) { Write-Host "Adding printer $($PrinterItem.Name) to print-cluster-1..." Start-Process -FilePath .\CreateRemotePrinter.bat -ArgumentList "$($PrinterItem.Name) `"$($PrinterItem.Driver)`" `"$($PrinterItem.Location)`" `"$($PrinterItem.Type)`"" -Wait } } $PrintersGPP.Save("\\COMDOM\SysVol\COMMON.DOMAIN\Policies\{f985a9ae-cb71-468b-8a99-e2c7f428aa2f}\User\Preferences\Printers\Printers.xml") $PrintersGPP.Save(".\Printers.xml") 
CreateRemotePrinter.bat
 @echo off SET PRTOOLS="c:\Windows\System32\Printing_Admin_Scripts\en-US" SET SETACL="SetACL.exe" SET PRNBRM="C:\Windows\System32\spool\tools\PrintBrm.exe" cscript /nologo %PRTOOLS%\prnport.vbs -s print-cl-node-1 -a -r %1 -h %1.common.domain -t -o raw -me cscript /nologo %PRTOOLS%\prnmngr.vbs -s print-cl-node-1 -a -p %1 -m %2 -r %1 cscript /nologo %PRTOOLS%\prncnfg.vbs -s print-cl-node-1 -t -p %1 -h %1 -l %3 -m %4 +shared %SETACL% -on \\print-cl-node-1\%1 -ot prn -actn ace -ace "n:STN-TN\%1;p:man_docs,print" %PRNBRM% -b -nobin -s print-cl-node-1 -f temp.printerexport %PRNBRM% -r -d printerexport -f temp.printerexport del /f /q temp.printerexport del /s /f /q printerexport\LMONS printerexport\PRTPROCS echo ^<SpoolerAttrib /^> > printerexport\BrmSpoolerAttrib.xml echo ^<PPROCS /^> > printerexport\PProcs.xml echo ^<PRINTERDRIVERS /^> > printerexport\BrmDrivers.xml echo ^<LMONS Arch="Windows x64"/^> > printerexport\BRMLMons.xml %PRNBRM% -b -d printerexport -f temp.printerexport del /s /f /q printerexport %PRNBRM% -r -s print-cluster-1 -f temp.printerexport -p all -o force del /f /q temp.printerexport cscript /nologo %PRTOOLS%\prnmngr.vbs -s print-cl-node-1 -d -p %1 cscript /nologo %PRTOOLS%\prnport.vbs -s print-cl-node-1 -d -r %1 
Summary Printers.xml file
 <?xml version="1.0" encoding="utf-8"?> <Printers clsid="{1F577D12-3D1B-471e-A1B7-060317597B9C}"> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="Delete All" status="Delete All" image="3" uid="{21097DBD-285D-48C3-B042-7746D7E6DA1B}" bypassErrors="1" disabled="1"> <Properties action="D" path="" default="0" deleteAll="1" port="" /> <Filters> <FilterRunOnce id="{F2537B78-C7D7-43DF-98D6-B32E90644825}" hidden="1" not="0" bool="AND" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BARAB-061" status="PRN-BARAB-061" image="2" uid="{43231EA0-A4A3-4F1A-8A25-95BC4FEFBCC6}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-BARAB-061" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-BARAB-061" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.142.1" max="192.168.142.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BARAB-061" status="PRN-BARAB-061" image="3" uid="{43231EA0-A4A3-4F1A-8A25-95BC4FEFBCC6}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-BARAB-061" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-BARAB-061" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.142.1" max="192.168.142.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BATAY-042" status="PRN-BATAY-042" image="2" uid="{4740604B-C403-4511-91B0-689A197260F3}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-BATAY-042" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-BATAY-042" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.128.1" max="192.168.129.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BATAY-042" status="PRN-BATAY-042" image="3" uid="{4740604B-C403-4511-91B0-689A197260F3}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-BATAY-042" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-BATAY-042" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.128.1" max="192.168.129.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BUY---001" status="PRN-BUY---001" image="2" uid="{457DB3FE-E35F-450E-B1D6-912F0D831573}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-BUY---001" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-BUY---001" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.44.1" max="192.168.44.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-BUY---001" status="PRN-BUY---001" image="3" uid="{457DB3FE-E35F-450E-B1D6-912F0D831573}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-BUY---001" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-BUY---001" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.44.1" max="192.168.44.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-ELAB-064" status="PRN-ELAB-064" image="2" uid="{52069D45-EF86-442D-A157-368D7510A1CF}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-ELAB-064" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="0" min="192.168.140.1" max="192.168.140.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-ELAB-064" status="PRN-ELAB-064" image="3" uid="{52069D45-EF86-442D-A157-368D7510A1CF}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-ELAB-064" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="1" min="192.168.140.1" max="192.168.140.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-EMPTY-002" status="PRN-EMPTY-002" image="2" uid="{475578CB-689F-463B-9710-AE207973146C}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-EMPTY-002" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-EMPTY-002" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.199.1" max="192.168.199.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-EMPTY-002" status="PRN-EMPTY-002" image="3" uid="{475578CB-689F-463B-9710-AE207973146C}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-EMPTY-002" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-EMPTY-002" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.199.1" max="192.168.199.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-KIRILL-081" status="PRN-KIRILL-081" image="2" uid="{421FC2DE-2E97-49FC-AEB0-3070B0166AD5}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-KIRILL-081" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="0" min="192.168.196.1" max="192.168.196.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-KIRILL-081" status="PRN-KIRILL-081" image="3" uid="{421FC2DE-2E97-49FC-AEB0-3070B0166AD5}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-KIRILL-081" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="1" min="192.168.196.1" max="192.168.196.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-KOTOV-013" status="PRN-KOTOV-013" image="2" uid="{4DFFBA1F-48D2-4824-B2EB-0AAD12B6A9D6}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-KOTOV-013" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-KOTOV-013" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.128.1" max="192.168.129.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-KOTOV-013" status="PRN-KOTOV-013" image="3" uid="{4DFFBA1F-48D2-4824-B2EB-0AAD12B6A9D6}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-KOTOV-013" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-KOTOV-013" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.128.1" max="192.168.129.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-LIPKI-003" status="PRN-LIPKI-003" image="2" uid="{4794D22E-6586-4A81-A85D-A21FB8B209CF}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-LIPKI-003" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="0" min="192.168.44.1" max="192.168.44.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-LIPKI-003" status="PRN-LIPKI-003" image="3" uid="{4794D22E-6586-4A81-A85D-A21FB8B209CF}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-LIPKI-003" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="1" min="192.168.44.1" max="192.168.44.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-NALTA-028" status="PRN-NALTA-028" image="2" uid="{35F6CF36-2A24-4A81-B061-8BE71CEC27EA}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-NALTA-028" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-NALTA-028" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.192.1" max="192.168.192.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-NALTA-028" status="PRN-NALTA-028" image="3" uid="{35F6CF36-2A24-4A81-B061-8BE71CEC27EA}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-NALTA-028" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-NALTA-028" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.192.1" max="192.168.192.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-PYSHM-004" status="PRN-PYSHM-004" image="2" uid="{45509B48-E7BC-4497-9665-86D4E1E96FE1}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-PYSHM-004" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="0" min="192.168.143.1" max="192.168.143.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-PYSHM-004" status="PRN-PYSHM-004" image="3" uid="{45509B48-E7BC-4497-9665-86D4E1E96FE1}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-PYSHM-004" default="0" port="" /> <Filters> <FilterIpRange bool="AND" not="1" min="192.168.143.1" max="192.168.143.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-TARUS-002" status="PRN-TARUS-002" image="2" uid="{398F4A94-530C-4E3B-8A30-4288D5E8854D}" userContext="1" bypassErrors="1"> <Properties action="U" comment="" path="\\print-cluster-1.common.domain\PRN-TARUS-002" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="0" name="COMDOM\PRN-TARUS-002" sid="" userContext="1" /> <FilterIpRange bool="AND" not="0" min="192.168.128.1" max="192.168.129.254" /> </Filters> </SharedPrinter> <SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="PRN-TARUS-002" status="PRN-TARUS-002" image="3" uid="{398F4A94-530C-4E3B-8A30-4288D5E8854D}" userContext="1" bypassErrors="1"> <Properties action="D" comment="" path="\\print-cluster-1.common.domain\PRN-TARUS-002" default="0" port="" /> <Filters> <FilterGroup bool="AND" not="1" name="COMDOM\PRN-TARUS-002" sid="" userContext="1" /> <FilterIpRange bool="OR" not="1" min="192.168.128.1" max="192.168.129.254" /> </Filters> </SharedPrinter> </Printers> 
Result on print server
image

Source: https://habr.com/ru/post/421211/


All Articles