脚本专栏 
首页 > 脚本专栏 > 浏览文章

PowerShell中使用PrintManagement管理打印机示例

(编辑:jimmy 日期: 2024/11/16 浏览:3 次 )

适用于Windows 8.1或者Windows Server 2012 R2

Windows 8.1和Windows Server 2012 R2引入了一个组件:“PrintManagement”,它包含了所有用来管理本地和远程机器打印机的命令。

下面的例子演示安装打印机驱动和打印机端口,先安装一个打印机,分享它,并设置一些属性。
复制代码 代码如下:
$ComputerName = $env:COMPUTERNAME
 
$DriverName = 'Samsung SCX-483x 5x3x Series XPS'
$IPAddress = '192.168.2.107'
$PortName = 'NetworkPrint_192.168.2.107'
$PrinterName = 'BWPrint'
$ShareName = 'Office 12'
 
Add-PrinterDriver -ComputerName $ComputerName -Name $DriverName
Add-PrinterPort -Name $PortName -ComputerName $ComputerName
Add-Printer -ComputerName $ComputerName -Name $PrinterName -DriverName $DriverName -Shared -ShareName $ShareName -PortName $PortName
Set-PrintConfiguration -ComputerName $ComputerName -PrinterName $PrinterName -PaperSize A4

当然,你要运行它,得确保调整变量 $IPAddress 指向真实存在的打印机地址。把$ComputerName 从本地机器名更改为远程机器名。

可以这样查看PrintManagement 组件中所有的PowerShell命令:
复制代码 代码如下:
PS> Get-Command -Module PrintManagement

CommandType     Name                                               ModuleName                                              
-----------     ----                                               ----------                                              
Function        Add-Printer                                        PrintManagement                                         
Function        Add-PrinterDriver                                  PrintManagement                                         
Function        Add-PrinterPort                                    PrintManagement                                         
Function        Get-PrintConfiguration                             PrintManagement                                         
Function        Get-Printer                                        PrintManagement                                         
Function        Get-PrinterDriver                                  PrintManagement                                         
Function        Get-PrinterPort                                    PrintManagement                                         
Function        Get-PrinterProperty                                PrintManagement                                         
Function        Get-PrintJob                                       PrintManagement                                         
Function        Read-PrinterNfcTag                                 PrintManagement                                         
Function        Remove-Printer                                     PrintManagement                                         
Function        Remove-PrinterDriver                               PrintManagement                                         
Function        Remove-PrinterPort                                 PrintManagement                                         
Function        Remove-PrintJob                                    PrintManagement                                         
Function        Rename-Printer                                     PrintManagement                                         
Function        Restart-PrintJob                                   PrintManagement                                         
Function        Resume-PrintJob                                    PrintManagement                                         
Function        Set-PrintConfiguration                             PrintManagement                                         
Function        Set-Printer                                        PrintManagement                                         
Function        Set-PrinterProperty                                PrintManagement                                         
Function        Suspend-PrintJob                                   PrintManagement                                         
Function        Write-PrinterNfcTag                                PrintManagement

其实,它们只是一些PowerShell函数,而不是编译的二进制命令。

上一篇:PowerShell中实现混淆密码示例
下一篇:Powershell展开对象数据结构并以JSON格式输出
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。