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