Page 1 sur 3
[RESOLU] Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 26 avr. 2022 - 16:36
par Albin
Bonjour,
Nous avons fait un script powershell qui permet de modifier la queue d'impression d'une imprimante.
voici le script en question
test.ps1: contient le script powershell
voici le script powershell associé
Code : Tout sélectionner
$OldServerName = "xxxxxxxxxxxxx"
$NewServerName = "yyyyyyyyyyyy"
#Get existing network printers
$CurrentPrinters = Get-WmiObject Win32_Printer | Where-Object {$_.Network -eq "true"} | Select-Object -ExpandProperty Name
#Remove existing network printers
Get-WmiObject -Class Win32_Printer | Where-Object {$_.Network -eq 'true'} | ForEach-Object {$_.delete()}
#Map the printers from a new server.
$CurrentPrinters | ForEach-Object {
$newprintername = $_.Replace( $OldServerName, $NewServerName )
Add-Printer -ConnectionName $newprintername
}
Le script ne fonctionne pas et J'aimerais savoir s'il vous plait quel peut être le problème.
Est ce que la fonction run PowerShell permet d'exécuter plusieurs lignes de commandes PowerShell?
Comment faire pour avoir voir les erreurs associés?
Merci
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 11:19
par dcardon
Bonjour Albin,
vous pouvez essayer la commande
Cordialement,
Denis
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 12:13
par Albin
Bonjour Denis,
J'ai testé la commande mais ça ne fonctionne toujours pas.
Cordialement,
Albin
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 14:04
par dcardon
c'est un peu limité comme information...
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 14:28
par Albin
Le problème que je rencontre c'est que lorsque je déploie le paquet contenant le script
sur une machine je n'ai pas d'erreur au niveau de la console Wapt mais ca ne fonctionne pas.
J'aimerais s'il vous plait savoir quel peut être la cause du problème . Merci
Cordialement,
Albin
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 14:36
par Albin
J'ai aussi activé l'exécution des scripts PowerShell sur le poste concerné
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 16:24
par Gaetan
Bonjour,
en dehors de WAPT le script est-il fonctionnel ?
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 16:27
par Albin
Bonjour Gaetan,
En effet, en dehors de WAPT le script est bien fonctionnel.
Cordialement
Albin
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 16:40
par Gaetan
Dans le paquet est-il possible d'exécuter chaque commande powershell avec un run_powershell plutôt qu'un script.
Ceci afin d'essayer de localiser le soucis
Re: Problème d'exécution d'un script PowerShell en utilisant la fonction run PowerShell
Publié : 27 avr. 2022 - 17:11
par Albin
Nous venons d'exécuter chaque commande du script avec run_powershell
voici le code:
Code : Tout sélectionner
run_powershell('$OldServerName = "xxxxxxxx"')
run_powershell('$NewServerName = "yyyyyyyy"')
run_powershell('$CurrentPrinters = Get-WmiObject Win32_Printer | Where-Object {$_.Network -eq "true"} | Select-Object -ExpandProperty Name')
run_powershell('-WmiObject -Class Win32_Printer | Where-Object {$_.Network -eq "true"} | ForEach-Object {$_.delete()}')
run_powershell('$CurrentPrinters | ForEach-Object { $newprintername = $_.Replace( $OldServerName, $NewServerName ) Add-Printer -ConnectionName $newprintername}')
Lorsque je déploie le paquet sur une machine, nous avons des erreurs dans la console wapt
voici les erreurs:
Code : Tout sélectionner
Installing:
Traceback (most recent call last):
File "C:\Program Files (x86)\wapt\setuphelpers_windows.py", line 1080, in run_powershell
result = run(cmd,
File "C:\Program Files (x86)\wapt\waptutils.py", line 2091, in run
raise CalledProcessErrorOutput(proc.returncode, cmd, ''.join(output+return_stderr))
waptutils.CalledProcessErrorOutput: Command 'powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKAC0AVwBtAGkATwBiAGoAZQBjAHQAIAAtAEMAbABhAHMAcwAgAFcAaQBuADMAMgBfAFAAcgBpAG4AdABlAHIAIAB8ACAAVwBoAGUAcgBlAC0ATwBiAGoAZQBjAHQAIAB7ACQAXwAuAE4AZQB0AHcAbwByAGsAIAAtAGUAcQAgACIAdAByAHUAZQAiAH0AIAB8ACAARgBvAHIARQBhAGMAaAAtAE8AYgBqAGUAYwB0ACAAewAkAF8ALgBkAGUAbABlAHQAZQAoACkAfQAgACAAfAAgAEMAbwBuAHYAZQByAHQAVABvAC0ASgBzAG8AbgAgAA==" ' returned non-zero exit status 1.
Output:#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">-WmiObject : Le terme «-WmiObject» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:2 : 1_x000D__x000A_</S><S S="Error">+ -WmiObject -Class Win32_Printer | Where-Object {$_.Network -eq "true" ..._x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : ObjectNotFound: (-WmiObject:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\wapt\common.py", line 3938, in install_wapt
exitstatus = setup.install()
File "C:\windows\TEMP\waptq24g89cv\setup.py", line 15, in install
File "C:\Program Files (x86)\wapt\setuphelpers_windows.py", line 1084, in run_powershell
raise CalledProcessErrorOutput(e.returncode, cmd, e.output)
waptutils.CalledProcessErrorOutput: Command 'powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKAC0AVwBtAGkATwBiAGoAZQBjAHQAIAAtAEMAbABhAHMAcwAgAFcAaQBuADMAMgBfAFAAcgBpAG4AdABlAHIAIAB8ACAAVwBoAGUAcgBlAC0ATwBiAGoAZQBjAHQAIAB7ACQAXwAuAE4AZQB0AHcAbwByAGsAIAAtAGUAcQAgACIAdAByAHUAZQAiAH0AIAB8ACAARgBvAHIARQBhAGMAaAAtAE8AYgBqAGUAYwB0ACAAewAkAF8ALgBkAGUAbABlAHQAZQAoACkAfQAgACAAfAAgAEMAbwBuAHYAZQByAHQAVABvAC0ASgBzAG8AbgAgAA==" ' returned non-zero exit status 1.
Output:#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">-WmiObject : Le terme «-WmiObject» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:2 : 1_x000D__x000A_</S><S S="Error">+ -WmiObject -Class Win32_Printer | Where-Object {$_.Network -eq "true" ..._x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : ObjectNotFound: (-WmiObject:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
CalledProcessErrorOutput: Command 'powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKAC0AVwBtAGkATwBiAGoAZQBjAHQAIAAtAEMAbABhAHMAcwAgAFcAaQBuADMAMgBfAFAAcgBpAG4AdABlAHIAIAB8ACAAVwBoAGUAcgBlAC0ATwBiAGoAZQBjAHQAIAB7ACQAXwAuAE4AZQB0AHcAbwByAGsAIAAtAGUAcQAgACIAdAByAHUAZQAiAH0AIAB8ACAARgBvAHIARQBhAGMAaAAtAE8AYgBqAGUAYwB0ACAAewAkAF8ALgBkAGUAbABlAHQAZQAoACkAfQAgACAAfAAgAEMAbwBuAHYAZQByAHQAVABvAC0ASgBzAG8AbgAgAA==" ' returned non-zero exit status 1.
Output:#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">-WmiObject : Le terme «-WmiObject» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:2 : 1_x000D__x000A_</S><S S="Error">+ -WmiObject -Class Win32_Printer | Where-Object {$_.Network -eq "true" ..._x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : ObjectNotFound: (-WmiObject:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
Cordialement,
Albin