Pagina 1 di 1

[RISOLTO] Distribuzione dello script su WAPT

Pubblicato: 5 dicembre 2024 - 15:53
per sete di conoscenza
- Versione WAPT installata: 2.5
- Sistema operativo del server: Linux 22.04
- Sistema operativo della macchina di amministrazione/creazione pacchetti: Windows Server 2016

Salve,
sto utilizzando la versione Discovery e vorrei sapere se esiste un modo per distribuire script (.ps1, .bat, ecc.) alle macchine agent. In caso affermativo, esiste una documentazione che mi possa guidare, dato che non sono riuscito a trovarla online?
Grazie!

Re: Distribuzione dello script su WAPT

Pubblicato: 6 dicembre 2024 - 14:17
di blemoigne
Ciao,
questo verrà eseguito utilizzando i comandi `run()` o `run_not_fatal()` per i file batch e `run_powershell`, `run_powershell_from_file()` o `run_powershell_script()` per i file PS1.
https://www.wapt.fr/apidoc/wapt-2.5/win ... elpers.run

Buona giornata,
Bertrand

Re: Distribuzione dello script su WAPT

Pubblicato: 6 dicembre 2024 - 16:53
per sete di conoscenza
blemoigne ha scritto: 6 dic 2024 - 14:17 Ciao,
verrà eseguito con i comandi run() o run_not_fatal() per i file batch, run_powershell, run_powershell_from_file() o run_powershell_script() per i file PS1.
https://www.wapt.fr/apidoc/wapt-2.5/win ... elpers.run

Buona giornata,
Bertrand
Ciao Bertrand,
Mi dispiace se le mie domande ti sembrano stupide e le risposte ti sembrano ovvie.
Sono davvero un principiante con il software e vorrei saperne di più per poter distribuire uno script.
- Per questo tipo di lavoro devo generare un modello di pacchetto vuoto nella console WAPT?
- Come (o dove) posso modificare un pacchetto tramite righe di comando?
Grazie !

Re: Distribuzione dello script su WAPT

Pubblicato: 6 dicembre 2024 - 18:01
di blemoigne
Innanzitutto, assicurati di avere un ambiente di sviluppo installato:
https://www.wapt.fr/fr/doc/wapt-create- ... pt-console.

Successivamente, devi creare un pacchetto vuoto. Di default, la directory per il pacchetto in fase di sviluppo si trova in c:\waptdev.
Puoi quindi inserire gli script nella directory del pacchetto.

Buon fine settimana,
Bertrand

Re: Distribuzione dello script su WAPT

Pubblicato: 9 dicembre 2024 - 16:01
per sete di conoscenza
blemoigne ha scritto: 6 dic 2024 - 18:01 Innanzitutto, devi assicurarti di aver installato un ambiente di sviluppo:
https://www.wapt.fr/fr/doc/wapt-create- ... pt-console

Quindi, devi creare un pacchetto vuoto. Per impostazione predefinita, la directory per il pacchetto in fase di sviluppo si trova in c:\waptdev.
Puoi inserire gli script nella directory del pacchetto.

Buon fine settimana,
Bertrand
Ho distribuito con successo un file .bat utilizzando il comando:

Codice: Seleziona tutto

def install():
    run(r"mon_script.bat")
Tuttavia, il file PowerShell dal repository non funziona. Ecco cosa ho fatto; puoi verificare se è corretto?

Codice: Seleziona tutto

def install():
    run_powershell(r"mon_script.ps1")
Grazie !

Re: Distribuzione dello script su WAPT

Pubblicato: 9 dicembre 2024 - 16:23
di fschelfaut
Buongiorno,

La funzione esegui_powershell() In attesa dell'esecuzione di un comando PowerShell.
Per eseguire uno script *.ps1È necessario utilizzare la funzione dedicata: esegui_powershell_script().

Ecco alcuni esempi di utilizzo:

Codice: Seleziona tutto

def install():
    run_powershell_script("mon_script.ps1")
    run_powershell('Write-Host "Je suis un test"')
Sono documentate tutte le funzioni utilizzabili in un pacchetto WAPT Qui
- https://www.wapt.fr/apidoc/wapt-2.6/win ... ell_script
- https://www.wapt.fr/apidoc/wapt-2.6/win ... powershell

Flavien

Re: Distribuzione dello script su WAPT

Pubblicato: 10 dicembre 2024 - 11:26
per sete di conoscenza
Buongiorno,

Continuo a ricevere errori relativi alla distribuzione degli script .ps1 :(
Nel pacchetto vuoto situato in C:\waptdev, dove ho inserito il mio file di script test.ps1:

Codice: Seleziona tutto

$sourceFilePath = "\\lan.xxx.xxx\NETLOGON\GPOs\Scripts\TEST WAPT\test.txt"
$destinationFilePath = "C:\test.txt"

if (Test-Path -Path $destinationFilePath) {
    exit
} else {
    Copy-Item -Path $sourceFilePath -Destination $destinationFilePath -Force
}
Ecco il codice in setup.py:

Codice: Seleziona tutto

# -*- coding: utf-8 -*-
from setuphelpers import *

def install():
    run_powershell_script(r"test.ps1")
Successivamente, ho creato il pacchetto utilizzando il comando in cmd:

Codice: Seleziona tutto

wapt-get build-package C:\waptdev\idvet-testscript_1.0.0_x64_Windows_PROD-wapt
Sul pacchetto vuoto, ho configurato l'architettura su x64 e il sistema operativo di destinazione su Windows.
Quando lo distribuisco, appare questo codice di errore:

Codice: Seleziona tutto

https://xxx.xxx.xxx.xxx/wapt/idvet-testscript_1.0.0-0_x64_windows_PROD.wapt : 5522 / 5522 (100%) (15 KB/s)
Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» 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:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]
Traceback (most recent call last):
  File "<string>", line 1943, in run
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 737, in run
    self._run()
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 1341, in _run
    raise Exception(_('Error during install of {}: errors in packages {}').format(
Exception: Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» 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:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]

Exception: Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» 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:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]
Traceback (most recent call last):
  File "<string>", line 1943, in run
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 737, in run
    self._run()
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 1341, in _run
    raise Exception(_('Error during install of {}: errors in packages {}').format(
Exception: Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» 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:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]
Da notare che ho provato ad avviare manualmente lo script sul PC host e funziona correttamente.
Ho anche provato con l'argomento run_powershell_script(r"test.ps1", output_format='text') senza sapere cosa fa realmente, il pacchetto viene avviato senza alcun problema ma lo script non funziona sull'host.

Avete qualche idea su questo problema che potrebbe aiutarmi? Grazie!

Re: Distribuzione dello script su WAPT

Pubblicato: 11 dicembre 2024 - 13:28
per sete di conoscenza
Buongiorno,

Alla fine ho trovato una soluzione per eseguire lo script. Ecco il mio codice nel file setup.py per eseguire lo script test.ps1, che si trova nel pacchetto WAPT vuoto:

Codice: Seleziona tutto

# -*- coding: utf-8 -*-
from setuphelpers import *
import os  # Import du module os pour gérer les chemins

def install():
    """
    Cette fonction est exécutée lors de l'installation du paquet.
    """
    current_dir = os.getcwd()
    script_path = os.path.join(current_dir, "test.ps1")

    # Exécuter le script PowerShell
    run(f"powershell.exe -ExecutionPolicy Bypass -File \"{script_path}\"")

def uninstall():
    """
    Cette fonction peut être utilisée pour désinstaller si nécessaire.
    """
    print("Uninstallation is not defined for this package.")
Grazie e buona giornata!