Page 2 of 3

Re: Problem executing a PowerShell script using the PowerShell run function

Published: April 27, 2022 - 5:45 PM
by dcardon
Hi Albin,

since you're defining variables, it's not possible to run them individually; you have to maintain the context.
In your last post, you have a "-WmiObject" command without the "Get"... It's normal that it crashes, probably an accidental copy-paste.
By the way, are you running `run_powershell_from_file` using `def session_setup()` or `def install()`? If it's using `def install()`, it's normal that it doesn't work; your code is context-dependent.

Regards,

Denis.

PS: Please put your code snippets and shell output in code blocks; it's much more readable.

Re: Problem executing a PowerShell script using the PowerShell run function

Published: April 28, 2022 - 9:46 AM
by Albin
Hello Denis,

indeed, we launch `run_powershell_from-file` using `def install()`.

Regards,

Albin

Re: Problem executing a PowerShell script using the PowerShell run function

Published: April 28, 2022 - 10:07 AM
by Albin
I re-ran my script using the run_powershell_from_file command
here is the code

Code: Select all

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

# Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls

def session_setup() :
    run_powershell_from_file("testwapt.ps1")
I'm getting errors in the console when I deploy to a machine.
Here are the errors:

Code: Select all

Traceback (most recent call last):
  File "C:\Program Files (x86)\wapt\common.py", line 3938, in install_wapt
    exitstatus = setup.install()
AttributeError: module '__waptsetup_ttmou6pwdf__' has no attribute 'install'
AttributeError: module '__waptsetup_ttmou6pwdf__' has no attribute 'install'
Sincerely,

Albin

Re: Problem executing a PowerShell script using the PowerShell run function

Published: April 28, 2022 - 11:29 AM
by sfonteneau

Code: Select all

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

def install():
    filecopyto('testwapt.ps1',r'c:\testwapt.ps1')

def session_setup() :
    run_powershell_from_file(r"c:\testwapt.ps1")
    
In PyScripter, run `execute install`, then `session_setup`

Re: Problem executing a PowerShell script using the PowerShell run function

Published: May 2, 2022 - 11:08 AM
by Albin
Good morning,
We tested your script, we don't have any errors in the Wapt console, but it still doesn't work

Code: Select all

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

def install():
    filecopyto('testwapt.ps1',r'c:\testwapt.ps1')

def session_setup() :
    run_powershell_from_file(r"c:\testwapt.ps1")
The copy of the testwapt.ps1 file is successful on the machine, but the script does not execute.

Sincerely,
Albin

Re: Problem executing a PowerShell script using the PowerShell run function

Published: May 2, 2022 - 11:36
by sfonteneau
On the machine where the package was launched, you can do the following:

Code: Select all

wapt-get session-setup nom_de_votre_paquet -f
To see what that says

Re: Problem executing a PowerShell script using the PowerShell run function

Published: May 2, 2022 - 12:02 PM
by Albin
Hello again,

I ran the command and I got this message

: Using config file: C:\Program Files (x86)\wapt\wapt-get.ini
Configuring testwapt.ps1 ...
2022-05-02 12:00:05,183 CRITICAL Exception: Package testwapt.ps1 is not installed

. Regards,

Albin

Re: Problem executing a PowerShell script using the PowerShell run function

Published: May 2, 2022 - 1:49 PM
by sfonteneau
Not the script, but the name of your package (package field in your package's control file)

Re: Problem executing a PowerShell script using the PowerShell run function

Published: May 2, 2022 - 4:19 PM
by Albin
I ran the command again with the package name.
Here's the message I got:
Using config file: C:\Program Files (x86)\wapt\wapt-get.ini
Configuring Printer_0-wapt ...
2022-05-02 16:17:16,250 CRITICAL Exception: Package Printer_0-wapt is not installed.

Regards,

Albin

Re: Problem executing a PowerShell script using the PowerShell run function

Published: May 3, 2022 - 9:34 AM
by sfonteneau
You specified the folder in waptdev and not the package name

So, judging by the folder name, I assume your package name is "Printer"

SO:

Code: Select all

wapt-get session-setup Imprimante -f