IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Installation d'imprimante à distance [PowerShell]


Sujet :

Scripts/Batch

  1. #1
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2017
    Messages
    66
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2017
    Messages : 66
    Points : 54
    Points
    54
    Par défaut Installation d'imprimante à distance
    Bonjour,

    J'ai récupéré un script sur le net permettant d'installer des imprimantes à distance. Mais bon vu mon niveau je galère pour l'adapter. Donc je commence déjà par essayer d'installer une imprimante sur mon propre poste avec le minimum de variables. Même comme ça plantage. Je vois pas ce qui bloque?

    tout va bien jusqu'à la création du port ip qui ce fait bien ensuite, ça coince pour l'installation du drivers.
    -J'ai vérifié le chemin du dossier des drivers ainsi que l'orthographe du .inf
    -Je lance le ps1 par un bat en tant qu'admin donc ça doit pas être une histoire de sécu


    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    ####################################################
        # Change these values to the appropriate values in your environment
     
        $PrinterIP = Read-Host -Prompt 'Indiquer IP IMPRIMANTE'
        $PrinterPort = "9100"
        $PrinterPortName =$PrinterIP
        $DriverName = "KONICA"
        $DriverPath = "c:\outils\KONICA"
        $DriverInf = "c:\outils\KONICA\KOAXWJ__.INF"
        $PrinterCaption = "KONICA MINOLTA C308"
        ####################################################
     
        ### ComputerList Option 1 ###
        # $ComputerList = @("lana", "lisaburger")
     
     
        #$ComputerList = @()
        #Import-Csv "$PSScriptRoot\Ordinateurs.csv" | `
        #% {$ComputerList += $_.Computer}
     
       Pause
     
        Function CreatePrinterPort {
        param ($PrinterIP, $PrinterPort, $PrinterPortName)
        $wmi = [wmiclass]"\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()
        }
     
        pause
     
        Function InstallPrinterDriver {
        Param ($DriverName, $DriverPath, $DriverInf)
        $wmi = [wmiclass]"\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()
        }
        pause
        Function CreatePrinter {
        param ($PrinterCaption, $PrinterPortName, $DriverName)
        $wmi = ([WMIClass]"\Root\cimv2:Win32_Printer")
        $Printer = $wmi.CreateInstance()
        $Printer.Caption = $PrinterCaption
        $Printer.DriverName = $DriverName
        $Printer.PortName = $PrinterPortName
        $Printer.DeviceID = $PrinterCaption
        $Printer.Put()
        }
        pause
     
         CreatePrinterPort -PrinterIP $PrinterIP -PrinterPort $PrinterPort `
         -PrinterPortName $PrinterPortName 
         InstallPrinterDriver -DriverName $DriverName -DriverPath `
         $DriverPath -DriverInf $DriverInf 
         CreatePrinter -PrinterPortName $PrinterPortName -DriverName `
         $DriverName -PrinterCaption $PrinterCaption
     
         pause
     
     
        ####################################################

    Exception lors de l'appel de «*Put*» avec «*0*» argument(s)*: «*Échec générique *»
    Au caractère E:\PrinterInstallerKonica\PrinterInstallerKonica - Copie de travail2.ps1:60 : 5
    +     $Printer.Put()
    +     ~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: ( : ) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Merci de votre aide.

  2. #2
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2017
    Messages
    66
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2017
    Messages : 66
    Points : 54
    Points
    54
    Par défaut
    Mon script fonctionne en local, il fallait juste mettre le nom exact du drivers dans drivers path et drivers path inf, est pas le renommé en Konica.
    Par contre dès que je veux l'exécuter sur une machine distante, il n'a pas l'air d'aimer le chemin que je lui donne pour le root\cimv2


    Morceau du code

    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $Computer = Read-Host -Prompt 'Indiquer nom de l''ordinateur'
        copy-item $PSScriptRoot\PILOTES\*  \\$Computer\c$\outils\ -Recurse
        $PrinterIP = Read-Host -Prompt 'Indiquer IP IMPRIMANTE'
        $PrinterPort = "9100"
        $PrinterPortName =$PrinterIP
        $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, $computer)
        $wmi = [wmiclass]"\\$Computer\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()
        }
     
    CreatePrinterPort -PrinterIP $PrinterIP -PrinterPort $PrinterPort `
         -PrinterPortName $PrinterPortName -ComputerName $computer

    erreur
    Impossible de convertir la valeur «\\\root\cimv2:win32_tcpipPrinterPort» en type «System.Management.ManagementClass».
    Erreur: «Paramètre non valide »
    Au caractère E:\PrinterInstallerKonica\PrinterInstallerKonica ok en local - Copie.ps1:27 : 5
    +     $wmi = [wmiclass]"\\$Computer\root\cimv2:win32_tcpipPrinterPort"
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : InvalidArgument : (:) [], RuntimeException
        + FullyQualifiedErrorId : InvalidCastToWMIClass
    Pourtant le script que j'ai récupéré à l'air "sérieux" et utilise cette syntaxe pour une machine distante.

    https://www.pdq.com/blog/how-to-add-...th-powershell/

    C'est indiqué pour Windows 8.1 / Server 2012 R2, mais ça tourne en local sur un poste W10 pro dc ça doit le faire aussi à distance sur un autre poste W10 pro, non?

    Faut il ajouter la classe System.Management.ManagementClass dans le code, si oui comment l'ajouter au code je connais pas trop la syntaxe .

    [void][System.Reflection.Assembly]::[System.Management.ManagementClass].................... ?

  3. #3
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2017
    Messages
    66
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2017
    Messages : 66
    Points : 54
    Points
    54
    Par défaut
    Bonjour

    J'ai trouvé ça :

    https://docs.microsoft.com/en-us/win...ing-powershell

    Je l'ai testé juste sur un bout de code pour la création de l'adresse ip sur un poste distant. Mais ça le fait toujours pas, PS ne reconnait pas la variable $computer que j'attribue à -ComputerName dans la fonction.... Pourquoi ? J'ai testé de mettre la variable $Computer à différents endroits ex \\$Computer\root\cimv2 ou encore -NameComputer $Computer -Namespace "root\cimv2" rien y fait

    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $Computer = Read-Host -Prompt 'Indiquer nom de l''ordinateur'
        #copy-item $PSScriptRoot\PILOTES\*  \\$Computer\c$\outils\ -Recurse -force
        $PrinterIP = Read-Host -Prompt 'Indiquer IP IMPRIMANTE'
        $PrinterPort = "9100"
        $PrinterPortName =$PrinterIP
        $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, $Computer)
        $wmi=Get-WmiObject -Namespace "root\cimv2" -Class Win32_tcpipPrinterPort -Impersonation 3 -ComputerName $Computer 
        #$wmi = [wmiclass]"\\$Computer\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()
        }
     
     
     
         CreatePrinterPort -PrinterIP $PrinterIP -PrinterPort $PrinterPort `
         -PrinterPortName $PrinterPortName -ComputerName $Computer


    Get-WmiObject : Impossible de valider l'argument sur le paramètre «ComputerName». L’argument est Null ou vide.
    Indiquez un argument qui n’est pas Null ou vide et réessayez.
    Au caractère C:\Users\8107705y\Desktop\PrinterInstallerKonica\PrinterInstallerKonicaconnectwmi.ps1:18 : 110
    + ... lass Win32_tcpipPrinterPort -Impersonation 3  -ComputerName $Computer
    +                                                                 ~~~~~~~~~
        + CategoryInfo          : InvalidData : (:) [Get-WmiObject], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
    Merci d'avance pour vos lumières.

  4. #4
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2017
    Messages
    66
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2017
    Messages : 66
    Points : 54
    Points
    54
    Par défaut
    j'ai résolu mon problème comme un grand .

    Pour info ça clochait au niveau des variables, dans les parametres de la fonction il fallait mettre $ComputerName et non pas $Comuter), idem pour la ligne du dessous.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. installation imprimante a distance
    Par yorukaze dans le forum Windows Serveur
    Réponses: 2
    Dernier message: 23/10/2007, 20h38
  2. Installer une imprimante réseau
    Par zipe dans le forum Réseau
    Réponses: 1
    Dernier message: 10/01/2006, 07h53
  3. Installer une imprimante sans le cd
    Par Lanny dans le forum Périphériques
    Réponses: 5
    Dernier message: 02/01/2006, 20h49
  4. Installation d'un service à distance
    Par Pico10 dans le forum Autres Logiciels
    Réponses: 3
    Dernier message: 02/12/2005, 08h41
  5. Réponses: 3
    Dernier message: 13/10/2005, 18h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo