美好的一天,
我准备了以下用于本地打印机安装的脚本,该脚本连接到具有IP地址的网络。
是否可以修改此脚本并使其在远程coimputers上安装打印机。我的要求是,如果我在我的笔记本电脑上运行这个脚本,那么它会询问我一个远程ComputerName,并在放入远程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 ####################################
######################################################################
此致 阿卜杜勒·瓦吉德
答案 0 :(得分:0)
您可以通过多种方式进行处理,我认为最简单的方法是安装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.