VBScriptから古いスクリプトをPowerShellに書き直すタスクが与えられました。このスクリプトは、基本的にテキストファイルの行を読み込み、その行に対応するプリンタをインストールし直してから、ドライバをインストールするだけです。Windows Server 2008 R2のプリンタ、削除プリンタなどの代替方法
このスクリプトは、仮想Citrixターミナルサーバー上で毎日実行されるため、現在リリースされているイメージとは独立してドライバをアップデートできます。
ここでは、最終的なスクリプトは次のようになります。.\scriptfilename.ps1 ".\Driverlist.txt"
ドライバリストちょうどこのようなラインで構成されています:そうは次のようにそれが呼び出される
# 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
"\\spbdn140\KM_Universal_PCL"
問題のショートに
このスクリプトを書くときは、わかりませんでしたプリンタ管理モジュールはWin 8およびServer 2012からのみ機能します。私たちのターミナルサーバーはすべてServer 2008を実行しています。
Server 2008のPowerShell v3-4で利用可能な情報(ドライバリスト)を達成しようとする方法はありますか?
この場合も、提供された情報だけを使用してドライバがターミナルサーバーにインストールされている必要があります。