1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| Write-host = "Choisir un Drivers"
$ouvrir1 = New-Object -comObject Shell.Application
$folder = $ouvrir1.BrowseForFolder(0, $message, 0, $PSScriptroot)
if ($folder -ne $null)
{
$folder.self.Path
}
$chemin=$folder.self.Path
$dossier=$chemin.split('\')[-1]
$commands = {
#$Computer = Read-Host -Prompt 'Indiquer nom de l''ordinateur'
#$DriverPath = "\\$Computer\c$\outils\KONICA MINOLTA C368SeriesPCL"
#$DriverInf = "\\$Computer\c$\outils\KONICA MINOLTA C368SeriesPCL\KOAXWJ__.INF"
do {
#Write-Host "le poste ne pingue pas, entrer un autre poste:"
$Computer = Read-Host -Prompt 'Indiquer nom de l''ordinateur'
}
until (Test-Connection $computer -Quiet -Count 2)
copy-item $chemin \\$Computer\c$\outils\ -Recurse -force
$list=Get-WmiObject -Class Win32_Printer -ComputerName $Computer | Select-Object Name,Location,PortName
$list.name
$PrinterIP = Read-Host -Prompt 'Indiquer IP IMPRIMANTE'
$PrinterPort = "9100"
$PrinterPortName =$PrinterIP
$DriverName = $dossier
$DriverPath = "\\$Computer\c$\outils\$dossier"
$fichierinf=Get-ChildItem -Recurse -Path "$chemin" -Name "*.inf"
$DriversInf = "\\$Computer\c$\outils\$dossier\$fichierinf"
$PrinterCaption = $dossier
Write-host = $PrinterPortName
Write-host = $DriverName
Write-host = $DriverPath
Write-host = $DriversInf
Write-host = $PrinterCaption
#$DriverName = "KONICA MINOLTA C368SeriesPCL"
#$DriverPath = "\\$Computer\c$\outils\KONICA MINOLTA C368SeriesPCL"
#$DriverInf = "\\$Computer\c$\outils\KONICA MINOLTA C368SeriesPCL\KOAXWJ__.INF"
#$PrinterCaption = "KONICA MINOLTA C308"
Function CreatePrinterPort {
param ($PrinterIP, $PrinterPort, $PrinterPortName, $ComputerName)
$wmi = [wmiclass]"\\$ComputerName\root\cimv2:win32_tcpipPrinterPort"
$wmi.psbase.scope.options.enablePrivileges = $true
$Port = $wmi.createInstance()
$Port.name = $PrinterPortName
$Port.hostAddress = $PrinterIP
$Port.portNumber = $PrinterPort
$Port.SNMPEnabled = $false
$Port.Protocol = 1
$Port.put()
}
Function InstallPrinterDriver {
Param ($DriverName, $DriverPath, $DriverInf, $ComputerName)
$wmi = [wmiclass]"\\$ComputerName\Root\cimv2:Win32_PrinterDriver"
$wmi.psbase.scope.options.enablePrivileges = $true
$wmi.psbase.Scope.Options.Impersonation = `
[System.Management.ImpersonationLevel]::Impersonate
$Driver = $wmi.CreateInstance()
$Driver.Name = $DriverName
$Driver.DriverPath = $DriverPath
$Driver.InfName = $DriverInf
$wmi.AddPrinterDriver($Driver)
$wmi.Put()
}
Function CreatePrinter {
param ($PrinterCaption, $PrinterPortName, $DriverName, $ComputerName)
$wmi = ([WMIClass]"\\$ComputerName\Root\cimv2:Win32_Printer")
$Printer = $wmi.CreateInstance()
$Printer.Caption = $PrinterCaption
$Printer.DriverName = $DriverName
$Printer.PortName = $PrinterPortName
$Printer.DeviceID = $PrinterCaption
$Printer.Put()
}
CreatePrinterPort -PrinterIP $PrinterIP -PrinterPort $PrinterPort `
-PrinterPortName $PrinterPortName -ComputerName $computer
InstallPrinterDriver -DriverName $DriverName -DriverPath `
$DriverPath -DriverInf $DriverInf -ComputerName $computer
CreatePrinter -PrinterPortName $PrinterPortName -DriverName `
$DriverName -PrinterCaption $PrinterCaption -ComputerName $computer
$again = ""
While($again -ne "o" -and $again -ne "n") { $again = Read-Host -prompt "Un autre poste (o=oui n=non)?"}
if ($again -eq "o")
{&$Commands}
elseif ($again -eq "n")
{exit}
}
&$Commands
#################################################### |
Partager