[SOLVED] Deploying Script on WAPT

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
thirst_for_knowledge
Messages: 14
Registration: December 5, 2024 - 3:33 PM

December 5, 2024 - 3:53 PM

- 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!
Last edited by soif_deconnaissances on Dec 11, 2024 - 13:30, edited 1 time.
- Installed WAPT version: 2.6.0.16714
- Server OS: Ubuntu
- Administration machine OS: Windows Server 2019
User avatar
blemoigne
Messages: 178
Registration: July 17, 2020 - 11:29

December 6, 2024 - 2:17 PM

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
thirst_for_knowledge
Messages: 14
Registration: December 5, 2024 - 3:33 PM

December 6, 2024 - 4:53 PM

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 !
- Installed WAPT version: 2.6.0.16714
- Server OS: Ubuntu
- Administration machine OS: Windows Server 2019
User avatar
blemoigne
Messages: 178
Registration: July 17, 2020 - 11:29

December 6, 2024 - 6:01 PM

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
thirst_for_knowledge
Messages: 14
Registration: December 5, 2024 - 3:33 PM

December 9, 2024 - 4:01 PM

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 !
- Installed WAPT version: 2.6.0.16714
- Server OS: Ubuntu
- Administration machine OS: Windows Server 2019
fschelfaut
Messages: 30
Registration: Nov 7, 2024 - 12:22

December 9, 2024 - 4:23 PM

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
thirst_for_knowledge
Messages: 14
Registration: December 5, 2024 - 3:33 PM

December 10, 2024 - 11:26

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!
- Installed WAPT version: 2.6.0.16714
- Server OS: Ubuntu
- Administration machine OS: Windows Server 2019
thirst_for_knowledge
Messages: 14
Registration: December 5, 2024 - 3:33 PM

December 11, 2024 - 1:28 PM

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!
- Installed WAPT version: 2.6.0.16714
- Server OS: Ubuntu
- Administration machine OS: Windows Server 2019
Locked