Seite 1 von 3

[GELÖST] Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion "run"

Veröffentlicht: 26. April 2022 – 16:36 Uhr
von Albin
Guten Morgen,
Wir haben ein PowerShell-Skript erstellt, mit dem Sie die Druckwarteschlange eines Druckers ändern können.
Hier ist das betreffende Skript

Code: Alle auswählen

run(r'powershell.exe -executionpolicy bypass ./test.ps1')
test.ps1: enthält das PowerShell-Skript

Hier ist das zugehörige PowerShell-Skript

Code: Alle auswählen

$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
}
Das Skript funktioniert nicht und ich würde gerne wissen, woran das liegen könnte.
Ermöglicht die PowerShell-Funktion „run“ die Ausführung mehrerer PowerShell-Befehlszeilen?
Wie kann ich die zugehörigen Fehler einsehen?
DANKE

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 - 11:19 Uhr
von dcardon
Hallo Albin,

Sie können den Befehl ausprobieren

Code: Alle auswählen

run_powershell_from_file("filename.ps1")
Aufrichtig,

Denis

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 - 12:13 Uhr
von Albin
Hallo Denis,

ich habe den Befehl getestet, aber er funktioniert immer noch nicht.

Viele Grüße,

Albin

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 14:04 Uhr
von dcardon
Das ist eine ziemlich begrenzte Informationsmenge...

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 14:28 Uhr
von Albin
Mein Problem besteht darin, dass beim Bereitstellen des Pakets, das das Skript enthält, Folgendes passiert:

Code: Alle auswählen

run_powershell_from_file("testwapt.ps1")
Auf einem Rechner erhalte ich keine Fehlermeldung in der Wapt-Konsole, aber es funktioniert trotzdem nicht.
Ich würde gerne wissen, was die Ursache des Problems sein könnte. Vielen Dank

Aufrichtig,

Albin

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 14:36 ​​Uhr
von Albin
Ich habe außerdem die Ausführung von PowerShell-Skripten auf dem betroffenen Rechner aktiviert

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 16:24 Uhr
von Gaetan
Hallo,

funktioniert das Skript auch außerhalb von WAPT?

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 16:27 Uhr
von Albin
Hallo Gaetan,

ja, abgesehen von WAPT funktioniert das Skript einwandfrei.

Viele Grüße,
Albin

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 16:40 Uhr
von Gaetan
Ist es innerhalb des Pakets möglich, jeden PowerShell-Befehl mit `run_powershell` anstatt mit einem Skript auszuführen?
Dies dient dazu, das Problem einzugrenzen.

Betreff: Problem beim Ausführen eines PowerShell-Skripts mit der PowerShell-Funktion „run“

Veröffentlicht: 27. April 2022 – 17:11 Uhr
von Albin
Wir haben gerade jeden Befehl des Skripts mit run_powershell ausgeführt
Hier ist der Code:

Code: Alle auswählen

 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}')
Beim Deployment des Pakets auf einen Rechner treten Fehler in der Wapt-Konsole auf
Hier sind die Fehler:

Code: Alle auswählen

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>
Aufrichtig,

Albin