VBScript에서 이전 스크립트를 PowerShell로 다시 작성하는 작업을 받았습니다. 이 스크립트는 기본적으로 텍스트 파일의 행을 읽고 다시 제거하기 전에 해당 행에 해당하는 프린터를 설치하므로 드라이버 만 설치됩니다.Windows Server 2008 R2의 프린터 추가, 프린터 제거 등의 대안
이 스크립트는 가상 Citrix 터미널 서버에서 매일 실행되므로 현재 릴리스 된 이미지와 독립적으로 드라이버를 업데이트 할 수 있습니다.
# 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"
문제점 : .\scriptfilename.ps1 ".\Driverlist.txt"
드라이버 목록이 바로 이와 같은 행으로 구성 여기
처럼 최종 스크립트가 어떻게 표시되는지를 보여줍니다이 스크립트를 작성할 때 나는 깨닫지 못했습니다. 프린터 관리 모듈은 Win 8 및 Server 2012에서만 작동합니다. 우리 터미널 서버는 모두 Server 2008을 실행하고 있습니다.
Server 2008의 PowerShell v3-4에서 제공되는 정보 (드라이버 목록)를 사용하여 달성하려는 방법은 있습니까?
최종 결과는 제공된 정보를 사용하여 드라이버가 터미널 서버에 설치되어 있어야한다는 것입니다.