# Step 1
# Specify the Standard TCP/IP Port with the network printer’s IP address (-HostAddress) and TCP port (-PortNumber). The port name should end with a colon ( : ) – here, Lexmark01:
$port = New-TpmsObjTcpIpPortRaw -Name Lexmark01: -PortNumber 9100 -HostAddress "192.168.209.204"
# Specify a printer name (here, PRN01-BLN) and a driver (here, Lexmark T644 (MS)) as well as the name of the port the printer is to be connected to. Here, the respective printer driver must already be installed on the target machine; this can be done manually or using New-TpmsObjDriver. Additionally, choose an existing printer as template to transfer its printer properties and settings to the printer to be created (-Template).
$printer = New-TpmsObjPrinter -Name "PRN01-BLN" -Driver "Lexmark T644 (MS)" -Port Lexmark01: -Template "Lexmark T644 (MS)"
# Note: If the template is on a remote machine, its name must be specified with FQDN address. Example:
-Template "\\cps48.ourdomain.local\Lexmark T644 (MS)".
The service of the Tpms.Agent that creates the printers must run with an account that has the permission to access the share of the template located on the remote computer.
# Set the printer to be shared. On this, specify a share name using Add-TpmsSharingInfo (here, PRN01-BLN) and add this information to the same variable (-Printers):
Add-TpmsSharingInfo -Printers ($printer) -Name "PRN01-BLN" -Mode Network
# Step 2
# Specify the Tpms.Agent address (here, tpms002.ourdomain.local) with TCP port using New-TpmsObjApplyAgent and collect the relevant printer and port settings with the parameters -Printers and -Ports in a data package (here, $srv):
$srv = New-TpmsObjApplyAgent -Name "tpms002.ourdomain.local" -Port 5050 -Printers ($printer) -Ports ($port)
# Step 3
# Send the specified data package to Tpms.Service which forwards it to the relevant Tpms.Agent. The agent will create port and printer and connect the printer to the port:
Start-TpmsApplyByAgent -Action Deploy -Servers ($srv) | Format-TpmsDispatch
Deploy enables this action – i. e., printer and port will be created. Remove disables it – i. e., printer and port will be deleted. Format-TpmsDispatch displays the output in table form.
For an example script with multiple printers see Script containing New-TpmsObjTcpIpPortRaw.