Question Imprimantes

Plus d'informations
il y a 16 ans 5 mois #5504 par LAPO
Imprimantes a été créé par LAPO
Bonjour,

je cherche à faire un script Powershell qui me permet d'installer une imprimante sur un poste du réseau.
Cette imprimante à une ip mais il n'y a pas de serveur d'impresion. Il faut donc d'abord ajouter l'imprimante en local puis lui assigner un port de type TCP\IP.

Les informations que j'ai trouvé sur les imprimantes sont toutes avec un serveur. :(

Merci pour votre aide,

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 16 ans 5 mois #5505 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Imprimantes
Salut,
ce script vbs répond-il au besoin ?
Si oui reste à le convertir...

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 16 ans 5 mois #5506 par LAPO
Réponse de LAPO sur le sujet Re:Imprimantes
c'est en effet ce que je veux mais le problème est que je ne connais rien au VBS.
Traduire les variables c'était pas trop dur mais je n'es aucune idée de comment traduire ceci par exemple :
[code:1]
Result = NewDriver.AddPrinterDriver(NewDriver)
[/code:1]
J'ai créé ma variable $NewDriver de type Win32_PrinterDriver. J'y ai mis le nom et le chemin du inf. Mais ici je bloque.

Y a t'il un site pour trouver facilement les correspondances VBS to powershell ?

encore merci,<br><br>Message édité par: tsunamidream, à: 19/10/09 14:43

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 16 ans 5 mois #5507 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Imprimantes
tsunamidream écrit:

Y a t'il un site pour trouver facilement les correspondances VBS to powershell ?

Sur ce site il y a un document d'aide à la conversion vbs-&gt;PowerShell, sinon sur Scripting guy .

Une ébauche, à tester :
[code:1]
#Param($Computer, $DriverName, $DriverInf, $IPAddress, $PortName)

# Specify the computer on which to create the printer.
$Computer = \&quot;.\&quot;

# Specify the printer driver's name (take this from the INF file).
$DriverName = \&quot;Canon iR2020 UFRII LT\&quot;

# Specify the .inf file's full path and filename.
$DriverInf = \&quot;\Canon Driver\English\32BIT\win2k_vista\CNLB0K.INF\&quot;

# Specify the printer's IP address.
$IPAddress = \&quot;10.0.0.140\&quot;

# Create the port name, then establish a WMI connection to the specified
# computer. Note that the loaddriver privilege is required to add the driver.
$PortName = \&quot;IP_$IPAddress\&quot;

# Step 1: Install the printer's driver.
$NewDriver = [WMIClass]\&quot;\\$Computer\root\cimv2:Win32_PrinterDriver\&quot;
$NewDriver.Name = $DriverName
$NewDriver.InfName = $DriverInf
$NewDriver.PSbase.Scope.Options.EnablePrivileges = $true
#Need SeLoadDriverPrivilege
$Result = $NewDriver.AddPrinterDriver(NewDriver)

Switch ($Result)
{
0 {Write-Host \&quot;Success : $DriverName\&quot;}
5 {Write-Host \&quot;Access denied : $DriverName\&quot;;Break}
1797 {Write-Host \&quot;The printer driver is unknown : $DriverName\&quot;;Break}
}

# Step 2: Create a TCP/IP printer port for the printer.
$ClassIPPrnPort= [wmiclass]\&quot;\\$Computer\root\cimv2:Win32_TCPIPPrinterPort\&quot;
$NewPort= $ClassIPPrnPort.CreateInstance()
$NewPort.HostAddress = $IPAddress
$NewPort.Name = $PortName

# Note that 1 = Raw, 2 = LPR
$NewPort.Protocol = 1
$ResultIP=$NewPort.Put()
#if $ResultIP Write- host \&quot;Created printer port: $PortName\&quot;

# Step 3: Add the printer.
$ClassPrinter= [wmiclass]\&quot;\\$Computer\root\cimv2:Win32_Printer\&quot;
$NewPrinter= $ClassIPPrnPort.CreateInstance()
$NewPrinter.DriverName = $DriverName
$NewPrinter.DeviceID = $DriverName
$NewPrinter.PortName = $PortName
$NewPrinter.Put()

$WSHNetwork= New-Object -com WScript.Network
$WSHNetwork.SetDefaultPrinter \&quot;Canon iR2020 UFRII LT\&quot;
#result ??
Write-Host \&quot;Created printer: $DriverName\&quot;
[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 16 ans 5 mois #5508 par LAPO
Réponse de LAPO sur le sujet Re:Imprimantes
bonjour,

Merci pour ton script.
Je l'ai modifié pour concorder avec ce dont j'ai besoin. Le problème ai que je n'ai pas d'erreur:blink: mais je n'ai pas non plus d'imprimante de créée.:(

Si vous avez des idées voici le code :
[code:1]#Param($Computer, $DriverName, $DriverInf, $IPAddress, $PortName)

# Specify the computer on which to create the printer.
$Computer = \&quot;.\&quot;

# Specify the printer driver's name (take this from the INF file).
$DriverName = \&quot;EPSON EPL-6200 Advanced\&quot;

# Specify the .inf file's full path and filename.
$DriverInf = \&quot;C:\epl6200_win2000_1.0a_en\EPOAPCFE.INF\&quot;

# Specify the printer's IP address.
$IPAddress = \&quot;10.206.177.223\&quot;

# Create the port name, then establish a WMI connection to the specified
# computer. Note that the loaddriver privilege is required to add the driver.
$PortName = \&quot;IP_$IPAddress\&quot;
Write-Host $PortName
# Step 1: Install the printer's driver.
$Driver = [WMIClass]'Win32_PrinterDriver'
$NewDriver = $Driver.CreateInstance()
$NewDriver.Name = $DriverName
$NewDriver.InfName = $DriverInf
#$NewDriver.PSbase.Scope.Options.EnablePrivileges = $true
#Need SeLoadDriverPrivilege
$Result = $Driver.AddPrinterDriver($NewDriver)
Write-Host $Result
Switch ($Result)
{
0 {Write-Host \&quot;Success : $DriverName\&quot;}
5 {Write-Host \&quot;Access denied : $DriverName\&quot;;Break}
1797 {Write-Host \&quot;The printer driver is unknown : $DriverName\&quot;;Break}
}

# Step 2: Create a TCP/IP printer port for the printer.
$ClassIPPrnPort= [wmiclass]'Win32_TCPIPPrinterPort'
$NewPort= $ClassIPPrnPort.CreateInstance()
$NewPort.HostAddress = $IPAddress
$NewPort.Name = $PortName

# Note that 1 = Raw, 2 = LPR
$NewPort.Protocol = 1
$ResultIP=$NewPort.Put()
#if $ResultIP Write- host \&quot;Created printer port: $PortName\&quot;

# Step 3: Add the printer.
$ClassPrinter= [wmiclass]'Win32_Printer'
$NewPrinter= $ClassPrinter.CreateInstance()
$NewPrinter.DriverName = $DriverName
$NewPrinter.DeviceID = $DriverName
$NewPrinter.PortName = $PortName
$ClassPrinter.AddPrinterConnection($NewPrinter)
$ClassPrinter.Put()

$WSHNetwork= New-Object -com WScript.Network
#$WSHNetwork.SetDefaultPrinter \&quot;Canon iR2020 UFRII LT\&quot;
#result ??
Write-Host \&quot;Created printer: $DriverName\&quot;
[/code:1]

encore merci,

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 16 ans 5 mois #5510 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Imprimantes
Une version qui fonctionne, le script VBS est erroné :
[code:1]
#Param($Computer, $DriverName, $DriverInf, $IPAddress, $PortName)

# Specify the computer on which to create the printer.
$Computer = \&quot;.\&quot;

# Specify the printer driver's name (take this from the INF file).
$DriverName = \&quot;Generic / Text Only\&quot;

# Specify the printer's IP address.
$IPAddress = \&quot;10.10.10.10\&quot; #LoopBack

# Create the port name, then establish a WMI connection to the specified
# computer. Note that the loaddriver privilege is required to add the driver.
$PortName = \&quot;IP_$IPAddress\&quot;

Write-Host $PortName
# Step 1: Install the printer's driver.
$Driver = [WMIClass]'Win32_PrinterDriver'
$NewDriver = $Driver.CreateInstance()
# champ suffisant, ensuite Windows se débrouille
# pour trouver le fichier .inf et l'installer
$NewDriver.Name = $DriverName
$ResultDrv = $Driver.AddPrinterDriver($DriverName)
Switch ($ResultDrv.ReturnValue)
{
0 {Write-Host \&quot;Success : $DriverName\&quot;}
5 {Write-Host \&quot;Access denied : $DriverName\&quot;;Break}
1797 {Write-Host \&quot;The printer driver is unknown : $DriverName\&quot;;Break}
default {Write-Host \&quot;Erreur : $(Result.ReturnValue)\&quot;;Break}
}


# Step 2: Create a TCP/IP printer port for the printer.
$ClassIPPrnPort= [wmiclass]'Win32_TCPIPPrinterPort'
$NewPort= $ClassIPPrnPort.CreateInstance()
$NewPort.HostAddress = $IPAddress
$NewPort.Name = $PortName
# Note that 1 = Raw, 2 = LPR
$NewPort.Protocol = 1
$NewPort.SNMPEnabled = $false
$ResultPort=$NewPort.Put()

# Step 3: Add the printer.
$ClassPrinter= [wmiclass]'Win32_Printer'
$NewPrinter= $ClassPrinter.CreateInstance()
$NewPrinter.DriverName = $DriverName
$NewPrinter.DeviceID = $DriverName
$NewPrinter.PortName = $PortName
$ResultPrinter=$NewPrinter.Put()
#The AddPrinterConnection WMI class method provides
#a connection to an existing printer on the NETWORK
[/code:1]
Cela fonctionne sur mon Poste : XP sp2 fr, posh v1 fr.

Au cas où cela ne fonctionnerai pas sur ton poste, essaie cette approche :
[code:1]rundll32 printui,PrintUIEntry /?[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.056 secondes
Propulsé par Kunena