Posts tagged: print

Add printer IP port using Powershell

The below will create a TCP/IP printer port using PowerShell:

$server=”servername”
$printerip=”1.1.1.1″
$port = ([WMICLASS]“\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort”).createInstance()
$port.Name=”IP_10.25.128.31″
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress=$printerip
$port.Put()
$port

To Automate it somewhat you can feed the parameters into it using arguments, you can run the commands using excel and copy into a batch file.

# This script requires 3 paramaters at the command in the form:
# .\CreatePrinterPort.ps1 servername IPAddress PortName
$server=$args[0]
$printerip=$args[1]
$port = ([WMICLASS]“\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort”).createInstance()
$port.Name=$args[2]
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress=$printerip
$port.Put()
$port

Share

Normal user cannot add a network printer on a Terminal Server

By default Windows 2000 and 2003 terminal services does not allow a non administration account to add a printer when they log onto a remote desktop connection. When they do attempt to install a printer the user gets the following error message.

You do not have sufficient access to your computer to connect to the selected printer.

To allow users to add a network printer either manually or via a logon script you will need to do the following:

  1. Open up local security policy by clicking “Start -> Programs -> Administrative Tools -> Local Security Policy“.
  2. Open Local Policies
  3. Open Security Policies
  4. On the Right hand side double-click “Prevent users from installing printer drivers”
  5. Click on Disabled and then Ok and then Close the Local Security Policy window.
  6. Reboot the computer

Apparently you can do a gpupdate /force (win 2003) or a secedit /REFRESHPOLICY MACHINE_POLICY /enforce (windows 2000) instead of rebooting but I have not tried that myself and its been just as easy to reboot the server.

You can also set this setting on the Terminal Servers OU through group policy if you have multiple Terminal Servers to save time.

Share

Delete Network Printers using VBScript

The script below will delete all network printers  from the user profile but will not remove any of the local printers. This is quite useful if you have roaming profiles and want to remove mapped printers before running computer/OU specific scripts to map other printers.

You will need to copy the below into a notepad document and save with a .vbs extension.

‘————————————————————————-

‘– Removes all network printers but not any local printers–

‘————————————————————————-

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)

Set colInstalledPrinters =  objWMIService.ExecQuery _
(“Select * from Win32_Printer Where Network = TRUE”)

For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

‘————————————————————————-

I have tested this under Windows XP and Windows 7 and appears to work properly. I don’t have any more Vista machines but it should work fine on that also.

Share