You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-05-04 15:35:08

taubry
Member
Registered: 2023-05-04
Posts: 3

deploy a powershell script

Hello,

I would like to deploy a powershell script using a task in glpi inventory.
In package management I added my ps1 script then I added an action:
cmd ScriptSO.ps1 /S
I also tried
ScriptSO.ps1 /S
powershell.exe -ExecutionPolicy Bypass -File ScriptSO.ps1

nothing works, in the logs the task is noted success but the script does not launch on the user's PC.

thanks in advance for those who help.

Have a good day.

Offline

#2 2023-05-05 08:45:47

gbougard
Moderator
From: Montpellier, France
Registered: 2021-07-21
Posts: 534
Website

Re: deploy a powershell script

Hi taubry,

in GLPI-Agent, I'm using the following syntax to start a PS script. Can you try it via the Deploy task ?

powershell -NonInteractive -ExecutionPolicy Unrestricted -File script.ps1

I think "-NonInteractive" option is the most important here.


GLPI-Agent developer from Teclib' and GLPI-Network team
Previously FusionInventory-Agent maintainer

Offline

#3 2023-05-05 09:57:38

taubry
Member
Registered: 2023-05-04
Posts: 3

Re: deploy a powershell script

Thank you for your answer.
the task ran successfully (green) but the script obviously did not run.
Here are the logs:

 
2023-05-05 11:50:32	Ok	job successfully completed
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1, processing success
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: ok, no check to evaluate.
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: exit status: `293'
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: error msg: `timeout'
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: --------------------------------
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1:
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: + CategoryInfo : OperationStopped: (:) [], COMException
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: + $MSWord.EmailOptions.EmailSignature.NewMessageSignature="expansion ...
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: Files\GLPI-Agent\var\http..__192.168.0.46_marketplace_glpiinventory_\deploy\workdir\6454b5295da53\ScriptSO.ps1:136 : 1
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: Au caractŠre C:\Program
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1: Op‚ration abandonn‚e (Exception de HRESULT : 0x80004004 (E_ABORT))
2023-05-05 11:50:32	En cours d'exécution	Actions:action #1:
2023-05-05 11:50:31	En cours d'exécution	Actions:action #1: + FullyQualifiedErrorId : GetContentWriterDirectoryNotFoundError,Microsoft.PowerShell.Commands.SetContentCommand
2023-05-05 11:50:31	En cours d'exécution	Actions:action #1: ================================
2023-05-05 11:50:31	En cours d'exécution	Actions:action #1: Started cmd: powershell -NonInteractive -ExecutionPolicy Unrestricted -File ScriptSO.ps1
2023-05-05 11:50:31	En cours d'exécution	Actions:action #1: ================================
2023-05-05 09:50:31	En cours d'exécution	Préparation des fichiers:success
2023-05-05 09:50:31	En cours d'exécution	Téléchargement de fichiers:success
2023-05-05 09:50:31	En cours d'exécution	Téléchargement de fichiers:ScriptSO.ps1 already downloaded
2023-05-05 09:50:31	En cours d'exécution	Téléchargement de fichiers:downloading files
2023-05-05 09:50:31	En cours d'exécution	Audits:all checks are ok
2023-05-05 09:50:31	En cours d'exécution	Audits:starting
2023-05-05 09:50:01	Préparé

I had the same kind of errors with the other commands.

Last edited by taubry (2023-05-05 14:09:00)

Offline

#4 2023-05-05 14:17:10

gbougard
Moderator
From: Montpellier, France
Registered: 2021-07-21
Posts: 534
Website

Re: deploy a powershell script

It seems your script is in trouble. Maybe it requires some user interaction or some configuration it can't retrieve from the local system account under the one the agent is running while running as a service.
Your error suggests it's related to a mail it is trying to create. Don't forget the used account is the local system one. You may just need some default values in your script in the case the environment is not providing the expected one.


GLPI-Agent developer from Teclib' and GLPI-Network team
Previously FusionInventory-Agent maintainer

Offline

#5 2023-05-05 15:16:20

taubry
Member
Registered: 2023-05-04
Posts: 3

Re: deploy a powershell script

Thank you very much, it is more and more clear.
My script retrieves information from the active directory to create an outlook signature.
When I run this script manually on the user's PC it works but when I run it via glpi I get an error.
I can't put default values because the script must be dynamic.
How to solve this problem?

Offline

#6 2023-05-05 15:38:47

gbougard
Moderator
From: Montpellier, France
Registered: 2021-07-21
Posts: 534
Website

Re: deploy a powershell script

Why not using GPO for such kind of problem ? What is the advantage of Deploy task against GPO ?
Or maybe you should better think to install the script so it is run the first time a user is connecting on a computer.


GLPI-Agent developer from Teclib' and GLPI-Network team
Previously FusionInventory-Agent maintainer

Offline

Board footer

Powered by FluxBB