PowerShell script file as custom action - Advanced Installer Community
Dorababu
Posts: 25
Joined: Fri Jun 16, 2017 8:37 am

PowerShell script file as custom action

Hello I have a powershell script which I am trying to execute it as custom action after the installation was done, but I am getting some error at the end while executing it. So can some one help me
TestPowerShel.aip
PowerShell
(13.18 KiB) Downloaded 550 times
Script I am trying to execute is as follows

Code: Select all

    #Creates Scheduled Task Actions
    $TaskAction1 = New-ScheduledTaskAction -Execute "C:\Users\MyUser\Downloads\SomeService.exe"

    #Creates Triggers
    $TaskTrigger  = New-ScheduledTaskTrigger -AtStartup
            
    #Assigns UserName
    $TaskUserName = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest

    #Creates Scheduled Task Settings
    $TaskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries

    #Creates Triggers
    $TaskTrigger  = New-ScheduledTaskTrigger -Daily -At 12:00:00
            
     #Create Scheduled Task
     $Task = New-ScheduledTask -Action $TaskAction1 -Principal $TaskUserName -Trigger $TaskTrigger -Settings $TaskSettings
            
     #Register Scheduled Task
     Register-ScheduledTask "SampleScheduledTask" -InputObject $Task -Force

     #Configure Scheduled Task
     $Task = Get-ScheduledTask -TaskName "SampleScheduledTask"
     $Task.Triggers.Repetition.Duration = ""
     $Task.Triggers.Repetition.Interval = "PT30M"

     #Update Scheduled Task
     $Task | Set-ScheduledTask -User "NT AUTHORITY\SYSTEM"
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: PowerShell script file as custom action

Hello,

Please ensure that your script works if it is manually executed(outside of the setup package). If it does and you still get an error, you could disable "Fail installation if custom action returns an error" option from your Run PowerShell Script File Custom Action.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dorababu
Posts: 25
Joined: Fri Jun 16, 2017 8:37 am

Re: PowerShell script file as custom action

When I execute the script it is working with out any issues and I am seeing the scheduler gets created, but some how from aip it is not working
Dorababu
Posts: 25
Joined: Fri Jun 16, 2017 8:37 am

Re: PowerShell script file as custom action

Sorin wrote:Hello,

Please ensure that your script works if it is manually executed(outside of the setup package). If it does and you still get an error, you could disable "Fail installation if custom action returns an error" option from your Run PowerShell Script File Custom Action.

Best regards,
Sorin
Fail installation if custom action returns an error" option from your Run PowerShell Script File Custom Action. if I do this how can be it is executed as a part of installation
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: PowerShell script file as custom action

Yes, the only difference is that the main installation process will ignore the exit code of your PS1 script. When this option is not set the installation process fails when an executable custom action returns an exit code different than 0.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dorababu
Posts: 25
Joined: Fri Jun 16, 2017 8:37 am

Re: PowerShell script file as custom action

But when I manually execute the same script it is working fine with out any issues. I am able to see the scheduler getting created.
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: PowerShell script file as custom action

Hello,

I've just noticed that your PowerShell script needs to run elevated. Please select "Run under the LocalSystem account with full privileges (no impersonation)" option for your custom action.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”