Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用脚本在远程计算机上安装打印机_Powershell_Powershell 2.0_Powershell 3.0 - Fatal编程技术网

Powershell 使用脚本在远程计算机上安装打印机

Powershell 使用脚本在远程计算机上安装打印机,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,你好 我准备了以下脚本,用于连接到具有IP地址的网络的本地打印机安装 是否可以修改此脚本并将其设置为在远程计算机上安装打印机。我的要求是,如果我在笔记本电脑上运行此脚本,它将要求我输入远程计算机名,在输入远程计算机名后,打印机将安装在那里 Write-Host "Develop Ineo 363 Printer Installation Initilizing !!" switch ([system.environment]::OSVersion.Version.Major) {

你好

我准备了以下脚本,用于连接到具有IP地址的网络的本地打印机安装

是否可以修改此脚本并将其设置为在远程计算机上安装打印机。我的要求是,如果我在笔记本电脑上运行此脚本,它将要求我输入远程计算机名,在输入远程计算机名后,打印机将安装在那里

   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 ####################################
######################################################################
问候
Abdul Wajid

您可以通过多种方式实现这一点,我认为最简单的方法是安装PSEXEC并将脚本存储在名为$Code的块中,然后将脚本写入目标计算机并使用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.