PowerShell v2添加打印机

时间:2016-11-23 16:30:01

标签: powershell printing powershell-v2.0

我试图创建一个PowerShell脚本,允许我添加和配置带有3个打印机实例的打印机。这就是我到目前为止所做的:

# Printer Info
$printerID = "HP Designjet Z3200 24in Photo"
$printerID1 = "HP Designjet Z3200 24in Photo - Canvas"
$printerID2 = "HP Designjet Z3200 24in Photo - Cover"
$printerIP = Read-Host 'What is the Poster Printer IP Address?'
$printerPort = "IP_$printerIP"
$printerModel = "HP Designjet Z3200 24in Photo"
# Speak with Ted about a specific place to put the poster driver pre-extracted
$driverINFPath = "C:\Velocity\HP WFP\Driver\hpdjz3200serieswx64pcl\hpi32pxs.inf"

# Build a new Local TCP Printer Port, naming it with values unique to the Printer ID:
$newPort = ([wmiclass]"Win32_TcpIpPrinterPort").CreateInstance()
$newPort.HostAddress = $printerIP
$newPort.Name = $printerPort
$newPort.Put()

# Add the printer
printui.exe /if /b "$printerID" /f "$driverINFPath" /u /r "$printerPort" /m "$printerModel"
printui.exe /if /b "$printerID1" /f "$driverINFPath" /u /r "$printerPort" /m "$printerModel"
printui.exe /if /b "$printerID2" /f "$driverINFPath" /u /r "$printerPort" /m "$printerModel"

我从早期帖子中复制了该部分的脚本端口部分。我试图找出.Put()是什么,我无法在任何地方找到它。任何帮助将非常感激。

1 个答案:

答案 0 :(得分:0)

  

... Windows PowerShell通过.NET Framework访问WMI   System.Management类。而不是使用SWbemObject,Windows   PowerShell使用System.Management.ManagementObject类。对于   无论好坏,此类使用名为Put的方法来保存更改   读写属性

来自TechNet,实际上是将VBScript Put_与PowerShell Put()调用进行比较。