2013-11-26 3 views
0

안녕하세요,스크립트를 사용하여 원격 컴퓨터에 프린터 설치하기

다음은 IP 주소가있는 네트워크에 연결된 로컬 프린터 설치용 스크립트입니다.

이 스크립트를 수정하여 원격 컴퓨터에 프린터를 설치할 수 있습니까? 내 요구 사항은 내 컴퓨터에서이 스크립트를 실행하면 원격 ComputerName을 물어보고 원격 컴퓨터 이름을 입력 한 후 프린터가 설치된다는 것입니다.

Write-Host "Develop Ineo 363 Printer Installation Initilizing !!" 

switch ([system.environment]::OSVersion.Version.Major) { 

    5 {$PrnVBSDir = "$env:windir\system32"} 
    6 {$PrnVBSDir = "$env:windir\System32\Printing_Admin_Scripts\en-US\"} 
} 

################################################################################ 
################# Installing the printer driver ################################ 
################################################################################ 
if ([System.IntPtr]::Size -eq 4) 
{ 
    Start-Process "RunDll32" -ArgumentList 'printui.dll PrintUIEntry /ia /m "Generic 42BW-4SeriesPCL" /h "x86" /v "Type 3 - User Mode" /f "\\helpdesk-pc\Drivers\Drivers\Printers\Develop 28BW-4\Driver CD-ROM\Driver\Drivers\PCL\EN\Win_x86\KOAYXJA_.inf"' -Wait 
    Write-Host "x86 Printer Driver deployment finished !!" -ForegroundColor Green 
} 

else 
{ 
    Start-Process "RunDll32" -ArgumentList 'printui.dll PrintUIEntry /ia /m "Generic 42BW-4SeriesPCL" /h "x64" /v "Type 3 - User Mode" /f "\\helpdesk-pc\Drivers\Drivers\Printers\Develop 28BW-4\Driver CD-ROM\Driver\Drivers\PCL\EN\Win_x64\KOAYXJA_.inf"' -Wait 
    Write-Host "x64 Printer Driver deployment finished !!" -ForegroundColor Green 
} 
###################################################################### 
################## Create the printer port ########################### 
###################################################################### 

$Port = ([wmiclass]"win32_tcpipprinterport").createinstance() 

$Port.Name = "Develop-HR" 
$Port.HostAddress = "192.168.24.20" 
$Port.Protocol = "1" 
$Port.PortNumber = "9100" 
$Port.SNMPEnabled = $false 
$Port.Description = "HR Develop Printer" 

$Port.Put() 

###################################################################### 
################# Installing The Printer ############################# 
###################################################################### 

$Printer = ([wmiclass]"win32_Printer").createinstance() 

$Printer.Name = "Develop-HR" 
$Printer.DriverName = "Generic 42BW-4SeriesPCL" 
$Printer.DeviceID = "Develop-HR" 
$Printer.Shared = $false 
$Printer.PortName = "Develop-HR" 
$Printer.Location = "HR Department" 
$Printer.Comment = "Printer + Photocopier + Scanner" 

$Printer.Put() 

###################################################################### 
############################# END #################################### 
###################################################################### 

감사 압둘 Wajid

답변

0

당신이에게 여러 가지 방법으로 접근 할 수, 내가 생각하는 가장 간단한 방법은 그 다음에 스크립트를 작성, PsExec를 설치하고 $ 코드라는 블록에 스크립트를 저장하는 것입니다 기계를 대상으로하고 psexec에

Write-Warning "Run this script using a account that has admin access to the target machine." 
$PCName = Read-Host "Computer Name" 

$Code = { 

switch ([system.environment]::OSVersion.Version.Major) { 
5 {$PrnVBSDir = "$env:windir\system32"} 
6 {$PrnVBSDir = "$env:windir\System32\Printing_Admin_Scripts\en-US\"} 
} 

if ([System.IntPtr]::Size -eq 4) 
{ 
Start-Process "RunDll32" -ArgumentList 'printui.dll PrintUIEntry /ia /m "Generic 42BW-4SeriesPCL" /h "x86" /v "Type 3 - User Mode" /f "\\helpdesk-pc\Drivers\Drivers\Printers\Develop 28BW-4\Driver CD-ROM\Driver\Drivers\PCL\EN\Win_x86\KOAYXJA_.inf"' -Wait 
Write-Host "x86 Printer Driver deployment finished !!" -ForegroundColor Green 
} 

else 
{ 
Start-Process "RunDll32" -ArgumentList 'printui.dll PrintUIEntry /ia /m "Generic 42BW-4SeriesPCL" /h "x64" /v "Type 3 - User Mode" /f "\\helpdesk-pc\Drivers\Drivers\Printers\Develop 28BW-4\Driver CD-ROM\Driver\Drivers\PCL\EN\Win_x64\KOAYXJA_.inf"' -Wait 
Write-Host "x64 Printer Driver deployment finished !!" -ForegroundColor Green 
} 

$Port = ([wmiclass]"win32_tcpipprinterport").createinstance() 

$Port.Name = "Develop-HR" 
$Port.HostAddress = "192.168.24.20" 
$Port.Protocol = "1" 
$Port.PortNumber = "9100" 
$Port.SNMPEnabled = $false 
$Port.Description = "HR Develop Printer" 

$Port.Put() 

$Printer = ([wmiclass]"win32_Printer").createinstance() 

$Printer.Name = "Develop-HR" 
$Printer.DriverName = "Generic 42BW-4SeriesPCL" 
$Printer.DeviceID = "Develop-HR" 
$Printer.Shared = $false 
$Printer.PortName = "Develop-HR" 
$Printer.Location = "HR Department" 
$Printer.Comment = "Printer + Photocopier + Scanner" 

$Printer.Put() } 

$Code | Out-File \\$PCName\C$\Logs\install-printer.ps1 -Width 230 -Force #Pipe the code block into a ps1 file on the target computer 
Start-Process "C:\Psexec.exe" -ArgumentList "\\$PCName -s Powershell.exe -ExecutionPolicy Bypass -File C:\Logs\install-printer.ps1 -Verb runas" -Wait #Start PSExec and run the ps1 file 
#ToDO:Clean up the target machine, remove the file afterwards. 

PSEXEC

으로 실행
관련 문제