加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-server-2008 – 通过Powershell创建网络打印机

发布时间:2020-12-13 23:04:44 所属栏目:Windows 来源:网络整理
导读:我正在尝试使用Power shell脚本创建网络打印机.下面的脚本创建端口没有任何问题,但不会创建队列.你能否确认这个脚本是否适用于 Windows Server 2008? (注意,您需要安装驱动程序才能使其正常工作). function CreatePrinterPort {Param ( [string]$IPAddress)
我正在尝试使用Power shell脚本创建网络打印机.下面的脚本创建端口没有任何问题,但不会创建队列.你能否确认这个脚本是否适用于 Windows Server 2008? (注意,您需要安装驱动程序才能使其正常工作).
function CreatePrinterPort {
Param (
 [string]$IPAddress
)

$port = [wmiclass]"Win32_TcpIpPrinterPort"
$newPort = $port.CreateInstance()
$newport.Name= "IP_$IPAddress"
$newport.SNMPEnabled=$false
$newport.Protocol=1
$newport.HostAddress= $IPAddress
Write-Host "Creating Port $ipaddress" -foregroundcolor "green"
$newport.Put()
}

function CreatePrinter {
    Param (
    [string]$PrinterName,[string]$DriverName,[string]$IPAddress,[string]$Location,[string]$Comment
    )

$print = [WMICLASS]"Win32_Printer"
$newprinter = $print.createInstance()
$newprinter.Drivername = $DriverName
$newprinter.PortName = "IP_$IPAddress"
$newprinter.Shared = $true
$newprinter.Sharename = $PrinterName
$newprinter.Location = $Location
$newprinter.Comment = $Comment
$newprinter.DeviceID = $PrinterName
Write-Host "Creating Printer $printername" -foregroundcolor "green"
$newprinter.Put()

}

CreatePrinterPort -IPAddress "Localhost"

CreatePrinter  -PrinterName Print1 -DriverName "HP LaserJet 4" -PortName "Localhost"`
                -Location "Office" -Comment "Test comment"

我得到的错误是在CreatePrinter函数上:

Exception calling “Put” with “0” argument(s): “Generic failure “

你的PortName不应该是“IP_ $IPAddress”而不是“Localhost”吗?
CreatePrinter  -PrinterName Print1 -DriverName "HP LaserJet 4" -PortName "IP_123.123.123.123" -Location "Office" -Comment "Test comment"

此外,您的DriverName必须是该驱动程序的确切名称.你不能选择它;它是由制造商指定的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读