ThinPrint Management Center – Documentation

Assigning the same template to all printers of a Connection

240 views 0

Purpose of this PowerShell script

With this script you can assign the same template printer to each printer of a specific Connection. This can speed up editing the printer list of a Connection in case you use more than one template for a spe­cific printer driver. On this:

  • Save the Management Center configuration to an XML file (with File→ Save Configuration).
  • Create a backup copy of this XML file.
  • In line 4 to 6 of the PowerShell script (see below), specify:
    • the path to the XML file with the variable $Path
    • the name of the Connection with the variable $Connection
    • the template name with the variable $Template
  • After running the PowerShell script, (re-)import the changed XML file to the Management Center.
Different templates are used bevor running the script

different templates are used bevor running the script

Running the script for changing the template of a specific connection

running the script for changing the template of a specific connection

The same template is used after running the script

the same template is used after running the script

 

PowerShell script

Set-StrictMode -Version "2.0"

######  Fill in the names of Management Center export file, of the template to be assigned and of the desired Connection  #####
$Path = "C:\temp\MC-export-file.xml"
$Template = "_Template_TP Output Gateway"
$Connection = "connection-name"

######  Further variables  #####
$Lines = @()
$Lines1 = @()
$Lines2 = @()
$Lines3 = @()
$Lines4 = @()
$PrinterIDs = @()

######  Reading data from XML file  #####
$Lines = Get-Content -path $Path -readcount 0
$output = "............... Reading the XML file .............."
$output
$output = "number of lines:"
$output
$counter1 = $Lines.length
$counter1

######  Identifying template ID and driver  #####
$Lines1 = $Lines
For($i=0; $i -lt $Lines1.Count; $i+=1){
   If( $Lines1[$i] | Select-String -Pattern $Template){
      $TemplateId = $Lines1[$i-1]
      $TemplateDriver = $Lines1[$i+1]
   }
   }
$match = $TemplateId -match "<TEMPLATEPRINTER_ID>([1-9][0-9]*)</TEMPLATEPRINTER_ID>"
$TemplateId = $matches[1]
$match = $TemplateDriver -match "<SERVERDRIVER_ID>([1-9][0-9]*)</SERVERDRIVER_ID>"
$TemplateDriver = $matches[1]

#####  Identifying connection ID  #####
$Lines2 = $Lines
$Connection = "<NAME>" + $Connection + "</NAME>"
For($i=0; $i -lt $Lines2.Count; $i+=1){
   $String1 = $Lines2[$i] | Select-String -Pattern $Connection
$String2 = $Lines2[$i-1] | Select-String -Pattern "<CONNECTION_ID>([1-9]([0-9]*))</CONNECTION_ID>"
   If( $Lines2[$i] -eq $String1 -and $Lines2[$i-1] -eq $String2){
      $ConnectionId = $Lines2[$i-1]
   }
}
$match = $ConnectionId -match "<CONNECTION_ID>([1-9]([0-9]*))</CONNECTION_ID>"
$ConnectionId = $matches[1]

#####  Identifying printer IDs of this connection  #####
$Lines3 = $Lines
$Pattern1 = "<FK_CONNECTION>" + $ConnectionID + "</FK_CONNECTION>"
For($i=0; $i -lt $Lines3.Count; $i+=1){
  If( $Lines3[$i] | Select-String -Pattern $Pattern1){
      $PrinterID = $Lines3[$i-1]
      $match = $PrinterID -match "<PK_IDENTIFIER>([1-9][0-9]*)</PK_IDENTIFIER>"
      $PrinterID = $matches[1]
      $PrinterIDs += $PrinterID
   }
}

#####  Changing template ID and driver of these printers  #####
$output = "............... Changing the XML file ............."
$output
$PrinterIDs | Foreach {
   $Lines4 = $Lines

Previous Page
Next Page

Was this helpful?