首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows 2008 R2中添加打印机、删除打印机等的替代方案

Windows 2008 R2中添加打印机、删除打印机等的替代方案
EN

Stack Overflow用户
提问于 2016-09-12 13:27:32
回答 1查看 1.5K关注 0票数 0

我的任务是从PowerShell中将一个旧脚本重写为VBScript。这个脚本基本上只是读取一行文本文件并安装与该行相对应的打印机,然后再删除它,以便只安装驱动程序。

这个脚本每天都在我们的虚拟Citrix终端服务器上执行,这样我们就可以独立于当前发布的映像更新驱动程序。

最后的脚本如下所示:

代码语言:javascript
复制
# Variables
Param([string]$FileName)
$DriverList = Get-Content $FileName
$ComputerName = hostname
$LogFile = "C:\Windows\Logs\PrinterCreation.log"
$SeperatorL = "═══════════════════════════════════════════════════════════════════════════════════════════════════════"
$SeperatorS = "═══════════════════════════════════════════"
$StartDate = Get-Date -Format "dd.MMM.yyyy HH:mm:ss"

# Log Header
"$SeperatorL" > $LogFile
" ServerName:   $ComputerName" >> $LogFile
" DriverList:   $FileName" >> $LogFile
" StartTime:    $StartDate" >> $LogFile
"$SeperatorL" >> $LogFile
"" >> $LogFile
"Beginning driver instalation process:" >> $LogFile

# Process the "$DriverList" by installing each printer on the list and  deleting the connection afterwards
foreach ($line in $DriverList) {
    "$SeperatorL" >> $LogFile
    " Print driver Installation:    $line" >> $LogFile

    # Installing the printer
    try {
        Add-Printer -ConnectionName $line -ErrorAction Stop
        Start-Sleep -s 10

        # Deleting the Printer
        try {
            Remove-Printer -Name $line -ErrorAction Stop
            " Printer installation successfull." >> $LogFile
        } catch {
            " INSTALATION NOT COMPLETE:     Printer was installed but connection could not be removed!" >> $LogFile
        }
    } catch [Microsoft.Management.Infrastructure.CimException] {
        " INSTALATION FAILED:           Printer driver cannot be found or does not exist!" >> $LogFile
    } finally {
        Start-Sleep -s 5
    }
}

# Log Footnote
$EndDate = Get-Date -Format "HH:mm:ss"
"$SeperatorL" >> $LogFile
"" >> $LogFile
"Instalation process completed:" >> $LogFile
"$SeperatorS" >> $LogFile
" End Time: $EndDate" >> $LogFile
"$SeperatorS" >> $LogFile

它的调用方式如下:.\scriptfilename.ps1 ".\Driverlist.txt"

驱动程序列表仅由如下行组成:"\\spbdn140\KM_Universal_PCL"

--中的问题

在编写这个脚本时,我没有意识到打印机管理模块只在Win 8和Server 2012上工作。我们的终端服务器都在运行Server 2008。

有什么方法可以实现我在服务器2008上使用PowerShell v3-4中可用的信息(驱动程序列表)所做的事情吗?

同样,最终的结果应该是仅仅使用所提供的信息将驱动程序安装在终端服务器上。

EN

回答 1

Stack Overflow用户

发布于 2016-09-12 14:13:52

我不这么认为,打印机cmdlet都是针对Win8 8/Server2008R2及更高版本的。不幸的是,有些cmdlet是操作系统特定的,更新PowerShell不包括它们。

但是,您可以运行一个PowerShell脚本,该脚本使用PrnMngr.vbs等工具调用cscript.exe。

下面是可以用来代替打印管理cmdlet的vbscript列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39451462

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档