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 :

Projet installation imprimante à distance [PowerShell]


Sujet :

Scripts/Batch

  1. #1
    Membre confirmé
    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
    Par défaut Projet installation imprimante à distance
    Bonjour,

    Je poste depuis quelques temps maintenant, car j'essaie de faire un soft sous Powershell me permettant d'installer des imprimantes à distance en automatisant la chose.

    Je touche au but, mais il a encore un gros bug... mon code ne fonctionne que pour une imprimante Konica Minolta C368 et encore que sous W10, sous W7 j'ai un message d'erreur 87 qui correspond d'après ces liens

    à une erreur de paramètre... Pour les autres imprimantes que ce soit du W7 ou W10 erreur 87

    https://docs.microsoft.com/en-us/win...-printerdriver

    http://codeandkeep.com/Rename-Computer-With-WMI/


    https://social.technet.microsoft.com...rverpowershell

    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
    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
     
        ####################################################
    Qaund ça fonctionne pas :

    Nom : fonctionne pas sous w7.JPG
Affichages : 410
Taille : 134,5 Ko

    Quand ça fonctionne :

    Nom : fonctionne sous w10.JPG
Affichages : 374
Taille : 110,8 Ko


    Merci pour vos lumières.

  2. #2
    Membre confirmé
    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
    Par défaut
    ça fonctionne le problème venait de la façon donc les chemins étaient déclarés

    De cette façon ça fonctionne

    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     #recuperation du nom du fichier .inf
        $fichierinf=Get-ChildItem -Recurse -Path "$chemin" -Name "*.inf"
     
        #création du chemin jusqu'au .inf
        $DriversInf = "\\$Computer\c$\outils\$dossier\$fichierinf"
     
        $DriverPath = "\\"+"$computer"+"\c$\outils\"+"$dossier"
        $DriverInf = "\\"+"$computer"+"\c$\outils\"+"$dossier"+"\"+"$fichierinf"
        $PrinterCaption = "$dossier"+"("+"$PrinterIP"+")"
        $DriverName = "$dossier"


  3. #3
    Membre confirmé
    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
    Par défaut Variable sur grandeur Mb Gb...
    Bonjour,

    J'ai fais un petit script me permettant de chercher des fichiers en fonction de leur taille, mon soucis et que quand je définis la taille de fichier en fixe dans ma commande pas de problème mais dès que j'essaie de la mettre en tant que variable ça ne fonctionne plus, est ce que c'est du au fait que la variable est renseigné dans une textbox et que la variable est en .txt? du coup aucune valeur n'est retournée...

    Voici mon ébauche de script :

    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
    Add-Type –AssemblyName System.Windows.Forms
       Add-Type -AssemblyName System.Drawing
     
       $MainForm = New-Object System.Windows.Forms.Form
       $MainForm.Text="Scanner"
       $MainForm.StartPosition =  "CenterScreen"
       $MainForm.Width = 600
       $MainForm.Height = 300
       $MainForm.TopMost = $True
     
     
     
       $labelfichier = New-Object System.Windows.Forms.Label
       $labelfichier.Location = New-Object System.Drawing.Point(40,20)
       $labelfichier.Size = New-Object System.Drawing.Size(120,20)
       $labelfichier.Text = 'Nom du fichier :'
       $MainForm.Controls.Add($labelfichier)
     
       $labelsize = New-Object System.Windows.Forms.Label
       $labelsize.Location = New-Object System.Drawing.Point(200,20)
       $labelsize.Size = New-Object System.Drawing.Size(120,20)
       $labelsize.Text = 'préciser la taille :'
       $MainForm.Controls.Add($labelsize)
     
     
     
     
       $tBoxfichier = New-Object System.Windows.Forms.TextBox
       $tBoxfichier.Location = New-Object System.Drawing.Point(40,40)
       $tBoxfichier.Size = New-Object System.Drawing.Size(100,30)
       $MainForm.Controls.Add($tBoxfichier)
       $tBoxfichier.add_Leave({
     
                           $ScanButton.visible = $true
    	                   })
     
       $fichier=$tBoxfichier.text
     
     
     
     
       $tBoxsize = New-Object System.Windows.Forms.TextBox
       $tBoxsize.Location = New-Object System.Drawing.Point(200,40)
       $tBoxsize.Size = New-Object System.Drawing.Size(100,20)
       $MainForm.Controls.Add($tBoxsize)
       $size=$size.text
       $tBoxsize.add_Leave({ Write-host = $size
     
                         })
     
       #([int]$string).gettype()		
     
       $ScanButton = New-Object System.Windows.Forms.Button
       $ScanButton.Location = New-Object System.Drawing.Point(400,30)
       $ScanButton.Size = New-Object System.Drawing.Size(100,35)
       $ScanButton.visible = $true
       $ScanButton.Text = 'Scanner'
       $ScanButton.add_click({
       write-host = $size 
                            <# $fichier=$tBoxfichier.text
                             $size=$tBoxsize.text 
                             
                             $result=Get-Childitem -Path C:\ -Include *$fichier* -Recurse -ErrorAction SilentlyContinue | where-object {$_.Length -gt $size.size } | Out-File -FilePath c:\temp\Result.txt
                           
                             Write-host = $result#>
                             })
     
     
     
       $MainForm.Controls.Add($ScanButton)
     
     
       $MainForm.ShowDialog()

    code qui fonctionne :

    Code codde : Sélectionner tout - Visualiser dans une fenêtre à part
    $result=Get-Childitem -Path C:\ -Include *$fichier* -Recurse -ErrorAction SilentlyContinue | where-object {$_.Length -gt 100mb } | Out-File -FilePath c:\temp\Result.txt

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

Discussions similaires

  1. [PowerShell] Installation d'imprimante à distance
    Par riko60 dans le forum Scripts/Batch
    Réponses: 3
    Dernier message: 21/04/2019, 09h16
  2. installation imprimante a distance
    Par yorukaze dans le forum Windows Serveur
    Réponses: 2
    Dernier message: 23/10/2007, 20h38
  3. aide sur projet installation intranet
    Par riven dans le forum Sujets
    Réponses: 3
    Dernier message: 09/06/2005, 13h51
  4. installation imprimante réseau
    Par Vanesse dans le forum Windows Serveur
    Réponses: 9
    Dernier message: 09/05/2005, 15h13

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