欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-14 08:05:17
适用于windows 8.1或者windows server 2012 r2 windows 8.1和windows server 2012 r2引入了一个组件:“pri...

适用于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函数,而不是编译的二进制命令。