Aerus
Posts: 3
Joined: Tue May 22, 2018 1:39 am

Can not run powershell through AI

HI I have a powershell script that i want to run before anything else is installed.
This is to install windows features required by our software package.
The Script is attached below at the end of this post.
I have tried as a custom PS inline and as a custom PS file both give an error
I have also tried moving the custom action that changes it to immediate and which was set to differed so it acted as Administrator
I am not sure where I am going wrong, If i execute the PS script on the machine desktop it runs and completes OK


This is the PS script that I want to Wrap inside AI
#Install Windows Features
set-executionpolicy unrestricted -Scope CurrentUser -Force
function Use-RunAs
{
# Check if script is running as Adminstrator and if not use RunAs
# Use Check Switch to check if admin

param([Switch]$Check)

$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()`
).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

if ($Check) { return $IsAdmin }

if ($MyInvocation.ScriptName -ne "")
{
if (-not $IsAdmin)
{
try
{
$arg = "-file `"$($MyInvocation.ScriptName)`""
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList $arg -ErrorAction 'stop'
}
catch
{
Write-Warning "Error - Failed to restart script with runas"
break
}
exit # Quit this session of powershell
}
}
else
{
Write-Warning "Error - Script must be saved as a .ps1 file first"
break
}
}



Use-RunAs

"Script Running As Administrator"

Sleep 3
Dism /Online /Get-Features /Format:Table
Dism /Online /Enable-Feature /FeatureName:IIS-DefaultDocument /All
Dism /Online /Enable-Feature /FeatureName:IIS-ASPNET45 /All
Dism /online /enable-feature /featureName:Microsoft-Windows-NetFx-VCRedist-Package /all
Dism /Online /Get-Features /Format:Table
cmd /c pause | out-null
Dan
Posts: 4513
Joined: Wed Apr 24, 2013 3:51 pm

Re: Can not run powershell through AI

Hi Peter,

Is there any message that you get during installation?

I would recommend you to install IIS, Visual C Redist and .Net Framework using our predefined support from the Prerequisite page. We have predefined prerequisites and windows features for this scenario.

Just go in the prerequsite page and select the desired windows features to enable and required runtime by your application.

Note that the Windows Installer does not support concurrent installation, limitation by design. I think this is why the installation fails.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”