Page 1 of 1

[SOLVED] Deploying Script on WAPT

Published: Dec 5, 2024 - 3:53 PM
out of thirst for knowledge
- WAPT version installed: 2.5
- Server OS: Linux 22.04
- Administration/package creation machine OS: Windows Server 2016

Hello,
I'm using the Discovery version and I'd like to know if there's a way to deploy scripts (.ps1, .bat, etc.) to agent machines? If so, is there any documentation to guide me, as I haven't been able to find it online?
Thank you!

Re: Deploying Script on WAPT

Published: Dec 6, 2024 - 2:17 PM
by blemoigne
Hello,
this will run using the `run()` or `run_not_fatal()` commands for batch files, and `run_powershell`, `run_powershell_from_file()`, or `run_powershell_script()` for PS1 files.
https://www.wapt.fr/apidoc/wapt-2.5/win ... elpers.run

Have a good day,
Bertrand

Re: Deploying Script on WAPT

Published: Dec 6, 2024 - 4:53 PM
out of thirst for knowledge
blemoigne wrote: Dec 6, 2024 - 2:17 PM Hello,
it will run with the commands run() or run_not_fatal() for batch files, run_powershell, run_powershell_from_file() or run_powershell_script() for PS1 files.
https://www.wapt.fr/apidoc/wapt-2.5/win ... elpers.run

Have a good day,
Bertrand
Hello Bertrand,
Sorry if my questions seem stupid and the answers seem obvious to you.
I am really a beginner with the software and I would like to know a little more detail in order to be able to deploy a script.
- Do I need to generate an empty package template in the WAPT console for this type of work?
- How (or where) can I edit a package via command lines?
Thank you !

Re: Deploying Script on WAPT

Published: Dec 6, 2024 - 6:01 PM
by blemoigne
First, you need to make sure you have a development environment installed:
https://www.wapt.fr/fr/doc/wapt-create- ... pt-console

Then, you need to create an empty package. By default, the directory for the package under development is located in c:\waptdev.
You can then put the scripts in the package directory.

Have a good weekend,
Bertrand

Re: Deploying Script on WAPT

Published: Dec 9, 2024 - 4:01 PM
out of thirst for knowledge
blemoigne wrote: Dec 6, 2024 - 6:01 PM First, you need to make sure you have installed a development environment:
https://www.wapt.fr/fr/doc/wapt-create- ... pt-console

Then, you need to create an empty package. By default, the directory for the package under development is located in c:\waptdev.
You can put the scripts in the package directory.

Have a good weekend,
Bertrand
I successfully deployed a .bat file using the command:

Code: Select all

def install():
    run(r"mon_script.bat")
However, the PowerShell file from the repository doesn't work. Here's what I did; can you check if it's correct?

Code: Select all

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

Re: Deploying Script on WAPT

Published: Dec 9, 2024 - 4:23 PM
by fschelfaut
Good morning,

The function run_powershell() Waiting for a PowerShell command to execute.
To run a script *.ps1You must use the dedicated function: run_powershell_script().

Here are some examples of use:

Code: Select all

def install():
    run_powershell_script("mon_script.ps1")
    run_powershell('Write-Host "Je suis un test"')
All functions usable in a WAPT package are documented here
- https://www.wapt.fr/apidoc/wapt-2.6/win ... ell_script
- https://www.wapt.fr/apidoc/wapt-2.6/win ... powershell

Flavien

Re: Deploying Script on WAPT

Published: Dec 10, 2024 - 11:26
out of thirst for knowledge
Good morning,

I keep getting errors related to the deployment of .ps1 scripts :(
In the empty package located at C:\waptdev, where I placed my test.ps1 scripts file:

Code: Select all

$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
}
Here is the code in setup.py:

Code: Select all

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

def install():
    run_powershell_script(r"test.ps1")
Next, I created the package using the command in cmd:

Code: Select all

wapt-get build-package C:\waptdev\idvet-testscript_1.0.0_x64_Windows_PROD-wapt
On the empty package, I configured the architecture to x64 and the target OS to Windows.
When I deploy it, this error code appears:

Code: Select all

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']]
Note that I did test manually launching the script on the host PC and it works correctly.
I also tested with the argument run_powershell_script(r"test.ps1", output_format='text') without knowing what it really does, the package is launched without any problem but the script does not work on the host.

Do you have any ideas on this problem that could help me? Thank you!

Re: Deploying Script on WAPT

Published: Dec 11, 2024 - 1:28 PM
out of thirst for knowledge
Good morning,

I finally found a solution to run the script. Here is my code in the setup.py file to run the test.ps1 script located in the empty WAPT package:

Code: Select all

# -*- 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.")
Thank you and have a good day!