Question Ajoût Imprimante

Plus d'informations
il y a 15 ans 1 mois #9294 par Lafafmentvotre
Ajoût Imprimante a été créé par Lafafmentvotre
Bonjour

Je suis un débutant dans l'utilisation de PowerShell.
Je suis à la recherche d'un script pour installer une imprimante avec Port TCP/IP.
J'ai pas mal cherché, trouvé et modifié pour en arriver à ce script
[code:1]#Param($Computer, $DriverName, $DriverInf, $IPAddress, $PortName)
#################
#VARIABLES
#################
$Computer = \".\" # Specify the computer on which to create the printer.
$DriverName = \"HP Universal Printing PCL 5\" # Specify the printer driver's name (take this from the INF file).
$IPAddress = \"10.10.11.11\" # Specify the printer's IP address.
#$DriverInf = \"Drivers\PCL5\hpcu104t.inf\" # Specify the inf path.
$DriverInf = \"\Drivers\PCL5\hpcu104t.inf\" # Specify the inf path.
$PrinterName=\"Test_PowerShell\" # Specify the printer name.
$PrinterLocation=\"My Location\" # Specify the printer location.
#################
#PORT
#################
$PortName = \"IP_$IPAddress\"
Write-Host $PortName
#################
#DRIVER
#################
$Driver = [WMIClass]'Win32_PrinterDriver'
$NewDriver = $Driver.CreateInstance()
$NewDriver.InfName = $DriverInf
$NewDriver.Name = $DriverName
$ResultDrv = $Driver.AddPrinterDriver($DriverName)
Switch ($ResultDrv.ReturnValue)
{
0 {Write-Host \"Success : $DriverName\"}
5 {Write-Host \"Access denied : $DriverName\";Break}
1797 {Write-Host \"The printer driver is unknown : $DriverName\";Break}
default {Write-Host \"Erreur : $(Result.ReturnValue)\";Break}
}
#################
#PORT PARAMETERS
#################
$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()
#################
#PRINTER
#################
$ClassPrinter= [wmiclass]'Win32_Printer'
$NewPrinter= $ClassPrinter.CreateInstance()
$NewPrinter.DriverName = $DriverName
$NewPrinter.DeviceID = $PrinterName
$NewPrinter.PortName = $PortName
$NewPrinter.Location = $PrinterLocation
$ResultPrinter=$NewPrinter.Put()[/code:1]

Lorsque je l'exécute, j'obtiens les erreurs suivantes :
[code:1]Exception calling \"AddPrinterDriver\" with \"1\" argument(s): \"Types non correspondants \"
At Z:\Pro\AutoIt Development\Seven\Printers_Install\PowerShell\PCL5.ps1:24 char:38
+ $ResultDrv = $Driver.AddPrinterDriver <<<< ($DriverName)
+ CategoryInfo : NotSpecified: (:«») [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvoke

The term 'Result.ReturnValue' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At Z:\Pro\AutoIt Development\Seven\Printers_Install\PowerShell\PCL5.ps1:30 char:19
+ Result.ReturnValue <<<<
+ CategoryInfo : ObjectNotFound: (Result.ReturnValue:«»String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Erreur :
Exception calling \"Put\" with \"0\" argument(s): \"Échec générique \"
At Z:\Pro\AutoIt Development\Seven\Printers_Install\PowerShell\PCL5.ps1:52 char:31
+ $ResultPrinter=$NewPrinter.Put <<<< ()
+ CategoryInfo : NotSpecified: (:«») [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException[/code:1]

Le port est bien créé mais le reste ne suit pas et je n'arrive pas à comprendre.

Pourriez-vous me guider svp ?

Merci par avance

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

Plus d'informations
il y a 15 ans 1 mois #9295 par xyz
Réponse de xyz sur le sujet Re:Ajoût Imprimante
Salut,
j'ai un doute sur la ligne suivante :
[code:1]$ResultDrv = $Driver.AddPrinterDriver($DriverName)[/code:1]
Ne serait-ce pas $NewSDriver en lieu et place de $DriverName ?

Tutoriels PowerShell

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

Plus d'informations
il y a 15 ans 1 mois #9296 par Lafafmentvotre
Réponse de Lafafmentvotre sur le sujet Re:Ajoût Imprimante
Hello

Merci pour la réponse, je viens de modifier.

J'ai désormais cette erreur :
[code:1]Exception calling \"Put\" with \"0\" argument(s): \"Échec générique \"
At Z:\Pro\AutoIt Development\Seven\Printers_Install\PowerShell\PCL5.ps1:51 char:31
+ $ResultPrinter=$NewPrinter.Put <<<< ()
+ CategoryInfo : NotSpecified: (:«») [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException[/code:1]

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

Plus d'informations
il y a 15 ans 1 mois #9305 par xyz
Réponse de xyz sur le sujet Re:Ajoût Imprimante
Il existe un bug sur la méthode Put() d'un objet 'Wmi'.
Test en Dupliquant l'appel à Put()...

Tutoriels PowerShell

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

Plus d'informations
il y a 15 ans 1 mois #9309 par Lafafmentvotre
Réponse de Lafafmentvotre sur le sujet Re:Ajoût Imprimante
Bonjour Laurent

Comme je disais en début de post, je suis un newbie dans l'utilisation de PowerShell.

Pourrais-tu m'expliquer la manipulation à effectuer ?

Merci

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

Plus d'informations
il y a 15 ans 1 mois #9311 par xyz
Réponse de xyz sur le sujet Re:Ajoût Imprimante
Essaie ceci :
[code:1]$ResultPrinter=$NewPrinter.Put()
$ResultPrinter=$NewPrinter.Put()[/code:1]
Peux-tu nous donner le lien du script d'origine ?

Tutoriels PowerShell

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

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