Page 1 of 1

Deploying a package containing a PowerShell script

Published: June 23, 2020 - 1:05 PM
by Guillaume_ccfd
Good morning,

Having little experience in preparing packages other than MSI/EXE or MSU, I am stuck on deploying a few lines of PowerShell.

Here is my setup.py file:

Code: Select all

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

def install():
    run_powershell(Get-NetIPInterface | where {$_.InterfaceAlias -eq "Wi-Fi"} | Set-NetIpInterface -InterfaceMetric 45)
    run_powershell(Get-NetIPInterface | where {$_.InterfaceAlias -match"Local"} | Set-NetIpInterface -InterfaceMetric 10)
    run_powershell(Get-NetIPInterface | where {$_.InterfaceAlias -match "Ethernet"} | Set-NetIpInterface -InterfaceMetric 10)
When I deploy the package to a machine, I get the following error:

Code: Select all

Traceback (most recent call last):
  File "C:\Program Files (x86)\wapt\common.py", line 3807, in install_wapt
    setup = import_setup(setup_filename)
  File "C:\Program Files (x86)\wapt\waptutils.py", line 1383, in import_setup
    py_mod = imp.load_source(modulename, setupfilename.encode(sys.getfilesystemencoding()))
  File "c:\windows\temp\wapt_p5e60\setup.py", line 6
    run_powershell(Get-NetIPInterface | where {$_.InterfaceAlias -eq "Wi-Fi"} | Set-NetIpInterface -InterfaceMetric 45)
                                              ^
SyntaxError: invalid syntax
SyntaxError: invalid syntax (setup.py, line 6)
Do you have any idea where the problem might be coming from?

Do you have any example files containing PowerShell scripts?

Thank you in advance!

Re: Deploying a package containing a PowerShell script

Published: June 23, 2020 - 1:45 PM
by sfonteneau
Like this?

Code: Select all

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

def install():
    run_powershell('Get-NetIPInterface | where {$_.InterfaceAlias -eq "Wi-Fi"} | Set-NetIpInterface -InterfaceMetric 45')
    run_powershell('Get-NetIPInterface | where {$_.InterfaceAlias -match"Local"} | Set-NetIpInterface -InterfaceMetric 10')
    run_powershell('Get-NetIPInterface | where {$_.InterfaceAlias -match "Ethernet"} | Set-NetIpInterface -InterfaceMetric 10')

Re: Deploying a package containing a PowerShell script

Published: June 23, 2020 - 5:09 PM
by Guillaume_ccfd
Thank you so much!

Indeed, the dimensions needed to be included!

In any case, it's a pleasure to be working on WAPT again. ;)