PowerShell script issues - Advanced Installer Community
dlenis
Posts: 40
Joined: Wed Nov 02, 2016 2:37 pm

PowerShell script issues

I have a PowerShell script that includes several functions. The script works when tested in PowerShell but fails when run in an Advanced Installer custom actions. Tested both as inline and attached PowerShell script. It seems that you are not able to call a function within the same script. Is this a limitation of Advanced Installer or bug?
  • Error received:
    Caught Exception: The term 'hello' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again
  • Test code:
    # Block for declaring the script parameters.
    Param()

    # Your code goes here.
    hello

    function hello
    {
    #tested with no logic and logic
    #do nothing
    }
Thank you,

Diego
Horatiu
Posts: 42
Joined: Tue Nov 29, 2016 1:19 pm

Re: PowerShell script issues

Hello dlenis,

You should declare your functions first and then call them, not the other way around. Powershell being an interpreter, goes through a script linearly top to bottom.

Test code:
# Block for declaring the script parameters.
Param()

function hello
{
#tested with no logic and logic
#do nothing
}

# Your code goes here.
hello

Hope it helps, have a great day!

Best regards,
~Horatiu
dlenis
Posts: 40
Joined: Wed Nov 02, 2016 2:37 pm

Re: PowerShell script issues

Horatiu,
That worked,

Thank you,

Diego

Return to “Common Problems”