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

所属分类: 脚本专栏 / PowerShell 阅读数: 578
收藏 0 赞 0 分享

适用于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交互式运行环境的几个小技巧

这篇文章主要介绍了PowerShell入门教程之高效使用PowerShell交互式运行环境的几个小技巧,本文也可以说是使用PowerShell的一些好习惯,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之Cmd命令与PowerShell命令相互调用的方法

这篇文章主要介绍了PowerShell入门教程之Cmd命令与PowerShell命令相互调用的方法,本文讲解了在Cmd命令中调用PowerShell命令、在PowerShell命令中调用Cmd命令的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之远程操作运行PowerShell的方法

这篇文章主要介绍了PowerShell入门教程之远程操作运行PowerShell的方法,本文讲解了配置远程基础结构、执行远程操作等内容,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之PowerShell管道介绍

这篇文章主要介绍了PowerShell入门教程之PowerShell管道介绍,本文讲解了管道的作用,并列出了几个使用实例,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之函数、脚本、作用域介绍

这篇文章主要介绍了PowerShell入门教程之函数、脚本、作用域介绍,本文所讲内容都是PowerShell的基础知识,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之访问.Net程序集、COM和WMI实例

这篇文章主要介绍了PowerShell入门教程之访问.Net程序集、COM和WMI实例,本文讲解了PowerShell作为Windows平台的脱水语言来访问其它资源的例子,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之创建和使用配置文件实例

这篇文章主要介绍了PowerShell入门教程之创建和使用配置文件实例,PowerShell的配置文件都是些普通的PowerShell脚本文件,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之编写和使用脚本模块实例

这篇文章主要介绍了PowerShell入门教程之编写和使用脚本模块实例,本文讲解了模块、脚本模块、编写脚本模块、模块安装路径、模块文件夹等内容,需要的朋友可以参考下
收藏 0 赞 0 分享

WMI入门教程之什么是WMI?

这篇文章主要介绍了WMI入门教程之什么是WMI?WMI有一组API,我们可以使用VBScript、PowerShell脚本还是利用C#的来访问WMI的类库,需要的朋友可以参考下
收藏 0 赞 0 分享

WMI入门教程之怎么使用WMI?

这篇文章主要介绍了WMI入门教程之怎么使用WMI?本文讲解了在软件中、PowerShell中、.NET中使用WMI的例子,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多