ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

Installer fails when trying to run Powershell command

Fri Nov 05, 2021 1:52 pm

Hi,

Using AI 12.7.2
Need to enable/install the .NET, WCF, HTTP Activation on Windows 2012, 2016 and 2019 servers.
The powershell command to do this is: Install-WindowsFeature NET-WCF-HTTP-Activation45 and i've tested this at the Powershell command line for all 3 versions of windows server successfully.

I've added a custom action - Run Powershell inline script and pasted in my command below.
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
Enable-WindowsFeature NET-WCF-HTTP-Activation45


When i build and run the installer on a server the installer fails with: The term 'Enable-WindowsFeature' is not
recognized as the name of a cmdlet, function, script file, or operable program.

Best regards,
Ian

Liviu
Posts: 1035
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Installer fails when trying to run Powershell command

Fri Nov 05, 2021 3:54 pm

Hello Ian,
i've tested this at the Powershell command line for all 3 versions of windows server successfully.
I've tested this on Windows Server 2019 and in Windows PowerShell ISE the command is not correct. So this is not related to Advanced Installer.
PS.png
PS.png (80.14KiB)Viewed 10061 times
After I looked into Microsoft docs, I couldn't find that command for Server 2019: Get-WindowsFeature

On their documentation is only mentioned Server 2012. And in my Server 2019 ISE I don't have the Enable-WindowsFeature command:
ServerFeature.png
ServerFeature.png (11.43KiB)Viewed 10061 times

In order to achieve what you want, you need to use any of these commands:

1. Install-WindowsFeature -name "NET-Framework-Features"

2. Get-WindowsFeature -Name SMTP-Server | Install-WindowsFeature

3. Add-WindowsFeature "NET-Framework-Features"


To get the list of the Windows Features and their names use the Get-WindowsFeature command.

I have tested this and works as expected:
installFeature.png
installFeature.png (42.54KiB)Viewed 10061 times

Please have a look on these articles:


1. How to Install Windows Features with Powershell?

2. Adding Server Roles and Features


Let me know if that helped.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

Re: Installer fails when trying to run Powershell command

Fri Nov 05, 2021 5:54 pm

Thanks very much Liviu,

I'll work through those and learn from it.

I've tried this on 2012 and 2019 servers (but not 2016 as there's not a test server free here just now). It works ok from the Powershell command line.
However i'm just wondering if there may be a different version of Powershell i haven't considered. It works with .NET 4.5 and 4.7 but i have noted the command is the same (*-Activation45).

PS C:\Users\Administrator> Install-WindowsFeature NET-WCF-HTTP-Activation45

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {HTTP Activation}


PS C:\Users\Administrator> Get-WindowsFeature NET-WCF-HTTP-Activation45

Display Name Name Install State
------------ ---- -------------
[X] HTTP Activation NET-WCF-HTTP-Activat... Installed

Thanks again and best regards,
Ian

Liviu
Posts: 1035
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Installer fails when trying to run Powershell command

Mon Nov 08, 2021 8:21 am

Hello Ian,

Please let me know if you encounter problems again.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

Re: Installer fails when trying to run Powershell command

Wed Nov 17, 2021 12:53 pm

Still working on this issue. The commands work perfectly well on the server Powershell ISE.
What i've found in the log when it fails during install is that installer appears to be using vocabulary from Powershell 1.0 and it doesn't understand the command (It didn't exist in 1.0) which is found in the later powershell vocab. Here is an extract from the log:

Dumping PowerShell invoke log ...
--> Found PowerShell path: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
--> PowerShell Script Execution Result Code: 574
--> PowerShell Script Execution log:
C:\Users\Administrator\AppData\Local\Temp\pss2D2.ps1 : Caught Exception: The term 'Install-WindowsFeature' is not
recognized as the name of a cmdlet, function, script file, or operable program

Is there a way to make it use the latest version of Powershell vocabulary found on the test server?
I have loaded Powershell v1.0 and examined the vocabulary and right enough, there is not command for 'Install-WindowsFeature'.
Additionally i have run the command 'get-host | Select-Object version' and it result is it shows the correct version runing on my workstaton and server as 5.1.x

Many thanks.

ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

Re: Installer fails when trying to run Powershell command

Wed Nov 17, 2021 1:12 pm

Ok, looks like i have figured it out - not a big fix at all ;)

For the powershell custom action whether it be inline or from script file, you must select '64-bit script' which forces the installer to use the latest version on the destination (workstation or server).
In turn this then allows installer to use the vocabulary set found in the latest powershell version on the machine it's being installed into.

Hope this is useful for others too as it was a bit of a conundrum.

Best regards,
Ian

Liviu
Posts: 1035
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Installer fails when trying to run Powershell command

Wed Nov 17, 2021 1:28 pm

Hi Ian,

That's awesome, I'm glad it works now!

Thank you for your follow-up on this. I am sure this will be of help for further users facing a same scenario as you.

Please let us know if there is anything else we could help you with and we will gladly assist.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”