Creating an import file for AutoConnect’s Map Additional Printers table

134 views 0

#####  ThinPrint Management Services script for creating or supplementing CSV files for AutoConnect's Map Additional Printers table (MAP) #####

# Here, the printer list is retrieved from a single ThinPrint Client.


#####  Fill in values to the variables $csvpath, $targetserver, $agentfqdn and $clientname as well as optionally $mapfilter and $iprange or $ipaddress  #####

$csvpath = "C:\MAP\MAP.csv"   # path to the Map Additional Printers CSV file, e. g. "C:\temp\MAP.csv"

$targetserver = "tpms003"   # central print server's address, e. g. "CPS003" or "192.168.130.1"

$agentfqdn = "tpms003.ourdomain.local" # FQDN of the machine the Tpms.Agent is running on, e. g. "CPS003.ourdomain.local"

$mapfilter = 3   # filter rules:

                 #   0 = * is set to columns User/Group, IP Range and Client Name

                 #   1 = client's IP range is set to column IP Range (specified using $iprange)

                 #   2 = client's IP address is set to column IP Range (specified using $ipaddress)

                 #   3 = client's hostname is set to column Client Name (specified using $clientname)

$iprange = "192.168.149.0/24"   # IP range entry in the IP Range column, e. g. "192.168.130.0/24", will be used in MAP if $mapfilter = 1

$ipaddress = "192.168.149.17"   # single IP address entry in the IP Range column, e. g. "192.168.130.35", will be used in MAP if $mapfilter = 2

$clientname = "client701"   # address for retrieving the printer list from ThinPrint Client ...

                 # ... as well as hostname entry in Client Name column, e. g. "LPS025", will be used in MAP if $mapfilter = 3


#####  Reading the printer list from the ThinPrint Client  #####

$client = New-TpmsObjTpClient -Name $clientname -Port 4000   # specifies ThinPrint Client's address and TCP port

$srva = New-TpmsObjQueryAgent -Name $agentfqdn -Port 5050 -ClientQueries ($client)   # specifies Tpms Agent's address and TCP port

$clientprinters = Start-TpmsQueryByAgent -Servers ($srva) | Format-TpmsDispatch   # retrieves the printer list from ThinPrint Client

$clientprinters   # displays the client printer list


#####  Preparing the Map Additional Printers CSV file  #####

   If( [system.io.file]::Exists($csvpath) -eq $True)   # checks whether the specified CSV file exists

      {

      $mapold = Get-Content $csvpath -readcount 0   # reads the current CSV file

      Set-Content $csvpath -value $mapold   # adds a linefeed after "¶"

      }

   Else

      {

      Add-Content -path $csvpath -value "DefaultPrinter,UserGroup,IPRange,ClientName,Destination"   # writes the table head if file didn't exist

      }

#####  Retrieving printer list from ThinPrint Client and supplementing the Map Additional Printers CSV file  #####

$clientprinters | foreach {

   If ($_ -is [ThinPrint.Tpms.Common.TpSrcPrn])

      {

      If ($mapfilter -eq 3)   # checks whether $mapfilter is set to 3

         {

         $mapnew = ([string]::Format("True,*,*,{0},\\{1}\{2}", $clientname,$targetserver,$_.Name))   # sets the row structure with client name

         }

      If ($mapfilter -eq 2)   # checks whether $mapfilter is set to 2

         {

         $mapnew = ([string]::Format("True,*,{0},*,\\{1}\{2}", $ipaddress,$targetserver,$_.Name))   # sets the row structure with IP address

         }

      If ($mapfilter -eq 1)   # checks whether $mapfilter is set to 1

         {

         $mapnew = ([string]::Format("True,*,{0},*,\\{1}\{2}", $iprange,$targetserver,$_.Name))   # sets the row structure with IP range

         }      

      If ($mapfilter -eq 0)   # checks whether $mapfilter is set to 0

         {

         $mapnew = ([string]::Format("True,*,*,*,\\{0}\{1}", $targetserver,$_.Name))   # sets the row structure with *

         }

      Add-Content $csvpath -Value $mapnew   # writes the table rows

      }   

   }
Previous Page
Next Page

Was this helpful?