Of course I prefer the third ...
Therefore, this example focuses on how you can quickly and without much headache create a printer using a simple powershell script. Task From the information in a list create a port + printer + driver. You want to specify the description and location. Decision The solution was found on the Web literally within the first ten minutes of digging. It took ten more minutes for a test run and checking the results.
Create a Script:
# function to create a printer
function CreatePrinter {
# Gets the name of the print server
$server = $ args[0]
# connect to WMI
$print = ([WMICLASS]"\$server\ROOT\cimv2:Win32_Printer")createInstance.()
# driver name
$print $. drivername = $args [1]
# Gets the name of the port
$print.PortName = $ args[2]
# default rasšaren printer
$print.Shared = $true
# name balls
$print.Sharename = $args [3]
# location
$print.Location = $args [4]
# comment
$print.Comment = $args [5]
# device ID
$print.DeviceID = $args [6]
# write the result
$print.Put()
}
# function to create a port
function CreatePrinterPort {
# get the server name
$server = $args[0]
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name= $args[1]
# SNMP we don't need. Why do we SNMP …?
$port.SNMPEnabled=$ false
$port.Protocol=1
# address
$port.HostAddress= $args[2]
$port.Put()
# import the data from a file
$printers = Import-Csv printers.csv
# obradatyvaem received data
foreach ($ printer in printers $) {
CreatePrinterPort $printer.Printserver printer $.Portname $printer.IPAddress
CreatePrinter $printer.Printserver printer $.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername
You may receive the following script error:
get-wmiobject win32_printer -computer "prnsrv"
get-wmiobject win32_printer -computer "prnsrv" | %{$_.portname}
To set up printers, you must assign permissions. In doing so, we help subinacl.exe utility, which can be found here.
F : Full Control M : Manage Documents P : Print
Now an example of assignment authority.
subinacl.exe /printer "\\PRNSRV\PRN-01" /revoke="LAB\Fin Users"
subinacl.exe /printer "\\PRNSRV\PRN-01" /grant="LAB\Group 01=MP"
By the way. This utility can be used to view permissions.
subinacl /verbose=1 /printer "\\PRNSRV\PRN-01" /display
subinacl /verbose=1 /printer "\\PRNSRV\*" /display
Richard Mueller edited Revision 4. Comment: Modified grammar
Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, modified title casing, added tag
Patris_70 edited Revision 1. Comment: added rn-US tag
Patris_70 edited Original. Comment: completed